lucee.Componentcoldbox.system.web.routing.Router
Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp www.ortussolutions.com --- Manages all the routing definitions for the application and exposes the ColdBox Routing DSL
Property Summary | ||||
---|---|---|---|---|
type | property | default | serializable | required |
string
|
baseURL
Base routing URL.
|
true
|
false
|
|
any
|
cachebox
DI *.
|
true
|
false
|
|
any
|
controller
|
true
|
false
|
|
boolean
|
enabled
Flag to enable/disable routing.
|
true
|
true
|
false
|
boolean
|
extensionDetection
Detect extensions flag, so it can place a 'format' variable on the rc.
|
true
|
true
|
false
|
any
|
flash
|
true
|
false
|
|
boolean
|
fullRewrites
This flag denotes if full URL rewrites are enabled or not.
|
false
|
true
|
false
|
any
|
log
|
true
|
false
|
|
any
|
logBox
|
true
|
false
|
|
boolean
|
looseMatching
Loose matching flag for regex matches.
|
false
|
true
|
false
|
struct
|
moduleRoutingTable
Modules Routing Table.
|
true
|
false
|
|
boolean
|
multiDomainDiscovery
This flag denotes that the routing service will discover the incoming base URL from the host + ssl + environment.
|
true
|
true
|
false
|
struct
|
namespaceRoutingTable
Namespace routing tables.
|
true
|
false
|
|
array
|
routes
The routing table.
|
true
|
false
|
|
string
|
thisModule
Fluent route construct for modules.
|
true
|
false
|
|
struct
|
thisRoute
Fluent route construct.
|
true
|
false
|
|
boolean
|
throwOnInvalidExtension
Throw an exception when extension detection is invalid or not.
|
false
|
true
|
false
|
string
|
validExtensions
Initialize the valid extensions to detect.
|
json,jsont,xml,cfm,cfml,html,htm,rss,pdf
|
true
|
false
|
any
|
wirebox
|
true
|
false
|
|
struct
|
withClosure
Fluent route construct for with routing.
|
true
|
false
|
Constructor Summary | |
---|---|
init()
Constructor. |
Method Summary | |
---|---|
any
|
addModuleRoutes(any pattern, any module, [boolean append='true'])
Register modules routes in the specified position in the main routing table, and returns itself. |
any
|
addNamespace(any pattern, any namespace, [boolean append='true'])
Register a namespace in the specified position in the main routing table, and returns itself. |
any
|
addRoute(string pattern, [string handler=''], [any action=''], [boolean packageResolverExempt='false'], [string matchVariables=''], [string view=''], [boolean viewNoLayout='false'], [boolean valuePairTranslation='true'], [any constraints='[runtime expression]'], [string module=''], [string moduleRouting=''], [string namespace=''], [string namespaceRouting=''], [boolean ssl='false'], [boolean append='true'], [any response=''], [numeric statusCode='200'], [any condition=''], [string name=''], [string domain=''], [any redirect=''], [string event=''], [string verbs=''], [string layout=''], [struct headers='[runtime expression]'], [struct rc='[runtime expression]'], [struct prc='[runtime expression]'], [string viewModule=''], [string layoutModule=''], [struct meta='[runtime expression]'])
Adds a route to dispatch and returns itself. |
any
|
apiResources(any resource, [any handler], [any parameterName='id'], [any only='[runtime expression]'], [any except='[runtime expression]'], [string module=''], [string namespace=''], [string pattern=''], [struct meta='[runtime expression]'])
Create all API RESTful routes for a resource. |
any
|
append()
Appends the route to the routing table. |
any
|
as(any name)
Registers the route as a named route. |
string
|
composeRoutingPath()
Composes the base routing path with no host or protocol. |
string
|
composeRoutingUrl()
Composes the base URL for the server using the following composition:. |
any
|
configure()
This method is to be implemented by the application router you create. |
any
|
constraints(any map)
Register a struct of constraints for the route. |
any
|
delete(any pattern, [any target])
Register a route with DELETE restriction. |
any
|
end()
This is a global route definition terminator. |
any
|
endWith()
End a with closure and returns itself. |
private struct
|
filterRouteActions(struct initial, [array only='[runtime expression]'], [array except='[runtime expression]'])
Get the correct route actions based on only and except lists. |
struct
|
findRouteByName(any name)
This function tries to find a specifc route by incoming name. |
any
|
get(any pattern, [any target])
Register a route with GET restriction. |
string
|
getBaseURL()
|
string
|
getCachebox()
|
string
|
getController()
|
string
|
getEnabled()
|
string
|
getExtensionDetection()
|
string
|
getFlash()
|
string
|
getFullRewrites()
|
string
|
getLog()
|
string
|
getLogBox()
|
string
|
getLooseMatching()
|
struct
|
getMemento()
A quick snapshot of the router state. |
array
|
getModuleRoutes(any module)
Get a module's routes array. |
string
|
getModuleRoutingTable()
|
struct
|
getModulesRoutingTable()
A quick ColdBox4 compatibility wrapper. |
string
|
getMultiDomainDiscovery()
|
array
|
getNamespaceRoutes(any namespace)
Get a namespace routes array. |
string
|
getNamespaceRoutingTable()
|
string
|
getRoutes()
|
string
|
getThisModule()
|
string
|
getThisRoute()
|
string
|
getThrowOnInvalidExtension()
|
string
|
getValidExtensions()
|
string
|
getWirebox()
|
string
|
getWithClosure()
|
any
|
group([struct options='[runtime expression]'], [any body])
This is the new approach to the with closure approach which has been marked as deprecated.
|
any
|
header(any name, any value, [boolean overwrite='true'])
Add a header to a route. |
any
|
headers(any map, [boolean overwrite='true'])
Appends a collection of header name-values to a pattern. |
any
|
includeRoutes(any location)
Includes a routes configuration file as an added import and returns itself after import. |
private struct
|
initRouteDefinition()
Construct a route definition construct. |
boolean
|
isValidExtension(any extension)
Verifies if an extension is valid in the Router. |
any
|
meta(any map, [boolean overwrite='true'])
Appends a collection of metadata name-values to a pattern. |
any
|
options(any pattern, [any target])
Register a route with OPTIONS restriction. |
any
|
packageResolver(boolean toggle)
Turn package resolver on/off. |
any
|
patch(any pattern, [any target])
Register a route with PATHC restriction. |
any
|
post(any pattern, [any target])
Register a route with POST restriction. |
any
|
prc(any name, any value, [boolean overwrite='true'])
Register a private request collection name-value pair if the route matches. |
any
|
prcAppend(any map, [boolean overwrite='true'])
Appends a collection of name-values to the PRC if the route matches. |
any
|
prepend()
Prepends the route to the routing table. |
private any
|
processRouteOptionals(struct thisRoute)
Process route optionals. |
any
|
processWith(any args)
process a with closure. |
any
|
put(any pattern, [any target])
Register a route with PUT restriction. |
any
|
rc(any name, any value, [boolean overwrite='true'])
Register a request collection name-value pair if the route matches. |
any
|
rcAppend(any map, [boolean overwrite='true'])
Appends a collection of name-values to the RC if the route matches. |
any
|
removeModuleRoutes(any module)
Remove a module's routing table and registration points and return itself. |
any
|
removeNamespaceRoutes(any namespace)
Remove a namespace's routing table and registration points and return itself. |
any
|
resources(any resource, [any handler], [any parameterName='id'], [any only='[runtime expression]'], [any except='[runtime expression]'], [string module=''], [string namespace=''], [string pattern=''], [struct meta='[runtime expression]'])
Create all RESTful routes for a resource. |
any
|
route(any pattern, [any target], [any name='[runtime expression]'])
Initiate a new route registration. |
any
|
setBaseURL(string baseURL)
|
any
|
setCachebox(any cachebox)
|
any
|
setController(any controller)
|
any
|
setEnabled(boolean enabled)
|
any
|
setExtensionDetection(boolean extensionDetection)
|
any
|
setFlash(any flash)
|
any
|
setFullRewrites(boolean fullRewrites)
|
any
|
setLog(any log)
|
any
|
setLogBox(any logBox)
|
any
|
setLooseMatching(boolean looseMatching)
|
any
|
setModuleRoutingTable(struct moduleRoutingTable)
|
any
|
setMultiDomainDiscovery(boolean multiDomainDiscovery)
|
any
|
setNamespaceRoutingTable(struct namespaceRoutingTable)
|
any
|
setRoutes(array routes)
|
any
|
setThisModule(string thisModule)
|
any
|
setThisRoute(struct thisRoute)
|
any
|
setThrowOnInvalidExtension(boolean throwOnInvalidExtension)
|
any
|
setValidExtensions(string validExtensions)
|
any
|
setWirebox(any wirebox)
|
any
|
setWithClosure(struct withClosure)
|
any
|
startup()
This method is called by the Routing Services to make sure the router is ready for operation. |
any
|
to(any event)
Terminates the route to execute an event. |
any
|
toAction(any action)
Terminates the route to execute a specific action or action struct. |
any
|
toHandler(any handler)
Terminates the route to execute a specific handler. |
any
|
toModuleRouting(any module)
Terminate the route to be the entry point for module routing. |
any
|
toNamespaceRouting(any namespace)
Terminate the route to be the entry point for namespace routing. |
any
|
toRedirect(any target, [any statusCode='301'])
Redirects to a route or full HTTP URL if the pattern matched. |
any
|
toResponse(any body, [numeric statusCode='200'])
Terminates the route to execute a response closure with optional status codes and texts. |
any
|
toView(any view, [any layout=''], [boolean noLayout='false'], [any viewModule=''], [any layoutModule=''])
Send a route to a view/layout combo. |
any
|
valuePairTranslation(boolean toggle)
Turns on/off the value pair translator from extra metadata in a URL. |
any
|
with([string pattern], [string handler], [any action], [boolean packageResolverExempt], [string matchVariables], [string view], [boolean viewNoLayout], [boolean valuePairTranslation], [any constraints], [string module], [string moduleRouting], [string namespace], [string namespaceRouting], [boolean ssl], [boolean append], [string domain])
Starts a with closure, where all arguments will be prefixed for the next concatenated addRoute() methods until an endWith() is called. |
any
|
withAction(any action)
Registers a pattern into a specific action for execution. |
any
|
withCondition(any condition)
Registers a closure/lambda that will be called once the route matches to verify if we can proceed and execute its terminators. |
any
|
withDomain(any domain)
Registers a pattern that must exist under a domain pattern. |
any
|
withHandler(any handler)
Registers a pattern into a specific handler for execution. |
any
|
withModule(any name)
Registers a pattern into a specific module routing table. |
any
|
withNamespace(any name)
Registers a pattern into a specific Namespace routing table. |
any
|
withSSL()
Forces SSL on the route. |
any
|
withVerbs(any verbs)
Restricts the route to specific HTTP Verbs. |
Methods inherited from class lucee.Component |
---|
None |
Constructor Detail |
---|
Constructor
Property Detail |
---|
Base routing URL
access
- publicrequired
- falsereturntype
- anyserializable
- trueDI *
access
- publicrequired
- falsereturntype
- anyinject
- cacheboxserializable
- truedelegate
- getCacheaccess
- publicrequired
- falsereturntype
- anyinject
- coldboxserializable
- truedelegate
- relocate,runEvent,runRouteFlag to enable/disable routing
access
- publicrequired
- falsereturntype
- anyserializable
- trueDetect extensions flag, so it can place a 'format' variable on the rc
access
- publicrequired
- falsereturntype
- anyserializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- coldbox:flashserializable
- trueThis flag denotes if full URL rewrites are enabled or not. Meaning if the `index` is in the path of the rewriter or not. The default value is **false**.
access
- publicrequired
- falsereturntype
- anyserializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- logbox:logger:{this}serializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- logboxserializable
- trueLoose matching flag for regex matches
access
- publicrequired
- falsereturntype
- anyserializable
- trueModules Routing Table
access
- publicrequired
- falsereturntype
- anyserializable
- trueThis flag denotes that the routing service will discover the incoming base URL from the host + ssl + environment. If off, then it will use whatever the base URL was set in the router.
access
- publicrequired
- falsereturntype
- anyserializable
- trueNamespace routing tables
access
- publicrequired
- falsereturntype
- anyserializable
- trueThe routing table
access
- publicrequired
- falsereturntype
- anyserializable
- trueFluent route construct for modules
access
- publicrequired
- falsereturntype
- anyserializable
- trueFluent route construct
access
- publicrequired
- falsereturntype
- anyserializable
- trueThrow an exception when extension detection is invalid or not
access
- publicrequired
- falsereturntype
- anyserializable
- trueInitialize the valid extensions to detect
access
- publicrequired
- falsereturntype
- anyserializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- wireboxserializable
- truedelegate
- getInstanceFluent route construct for with routing
access
- publicrequired
- falsereturntype
- anyserializable
- trueMethod Detail |
---|
Register modules routes in the specified position in the main routing table, and returns itself
pattern
- The pattern to match against the URLmodule
- The module to load routes forappend
- Whether the module entry point route should be appended or pre-pended to the main routes array. By default we append to the end of the arrayRegister a namespace in the specified position in the main routing table, and returns itself
pattern
- The pattern to match against the URL.namespace
- The name of the namespace to registerappend
- Whether the route should be appended or pre-pended to the array. By default we append to the end of the arrayAdds a route to dispatch and returns itself.
pattern
- The pattern to match against the URL.handler
- The handler to execute if pattern matched.action
- The action in a handler to execute if a pattern is matched. This can also be a structure based on the HTTP method(GET,POST,PUT,DELETE). ex: {GET:'show', PUT:'update', DELETE:'delete', POST:'save'}packageResolverExempt
- If this is set to true, then the interceptor will not try to do handler package resolving. Else a package will always be resolved. Only works if :handler is in a patternmatchVariables
- DEPRECATED: Use RC or PRC structs instead. A string of name-value pair variables to add to the request collection when this pattern matches. This is a comma delimited list. Ex: spaceFound=true,missingAction=onTestview
- The view to dispatch if pattern matches. No event will be fired, so handler,action will be ignored.viewNoLayout
- If view is chosen, then you can choose to override and not display a layout with the view. Else the view renders in the assigned layout.valuePairTranslation
- Activate convention name value pair translations or not. Turned on by defaultconstraints
- A structure of regex constraint overrides for variable placeholders. The key is the name of the variable, the value is the regex to try to match.module
- The module to add this route tomoduleRouting
- Called internally by addModuleRoutes to add a module routing route.namespace
- The namespace to add this route tonamespaceRouting
- Called internally by addNamespaceRoutes to add a namespaced routing route.ssl
- Makes the route an SSL only route if true, else it can be anything. If an ssl only route is hit without ssl, the interceptor will redirect to it via sslappend
- Whether the route should be appended or pre-pended to the array. By default we append to the end of the arrayresponse
- An HTML response string to send back or a closure to be executed that should return the response. The closure takes in a 'params' struct of all matched params and the string will be parsed with the named value pairs as ${param}statusCode
- The HTTP status code to send to the browser response.condition
- A closure or UDF to execute that MUST return true to use route if matched or false and continue.name
- The name of the routedomain
- The domain to match, including wildcardsredirect
- If used, then the route will dispatch a relocation to this value as the new route using the `statuCode` default of 301 (Permanent) or if you define a `statusCode` we will use that.event
- The event to execute if route matchesverbs
- The allowed HTTP Verbs for the routelayout
- The view layout to useheaders
- The HTTP headers to attach to the response if route matchesrc
- The RC name value pairs to attach if the response matchesprc
- The PRC name value pairs to attach if the response matchesviewModule
- The module the view belongs tolayoutModule
- The module the layout belongs tometa
- Additional metadata to add to the incoming routeCreate all API RESTful routes for a resource. It will provide automagic mappings between HTTP verbs and URLs to event handlers and actions. By convention the following rules apply - The name of the resource maps to the name of the event handler - The default paremeter name is called `:id` - The available actions are: index, create, show, update, delete Example: `resource = photos` Then we will create the following routes: - `/photos` : `GET` -> `photos.index` Get a list of photos from the API - `/photos` : `POST` -> `photos.create` Create a new photo - `/photos/:id` : `GET` -> `photos.show` Get a specific photo from the API - `/photos/:id` : `PUT/PATCH` -> `photos.update` Update a specific photo - `/photos/:id` : `DELETE` -> `photos.delete` Delete a specific photo
resource
- The name of a single resource to maphandler
- The handler for the route. Defaults to the resource name.parameterName
- The name of the id/parameter for the resource. Defaults to `id`.only
- Limit routes created with only this list or array of actions, e.g. "index,show"except
- Exclude routes with an except list or array of actions, e.g. "show"module
- If passed, the module these resources will be attached to.namespace
- If passed, the namespace these resources will be attached to.pattern
- If passed, the actual URL pattern to use, else it defaults to `/#arguments.resource#` the name of the resource.meta
- A struct of metadata to store with ALL the routes created from this resourceAppends the route to the routing table. By default all routes are appended.
route( "hello", "main.index" ).append();
Registers the route as a named route
route( "hello", "main.index" ).as( "main" )
name
- The name to use for the routeComposes the base routing path with no host or protocol
Composes the base URL for the server using the following composition: - protocol - host + port - routing app mapping - full Url routing or front controller routing
This method is to be implemented by the application router you create. This is where you will define all your routing.
Register a struct of constraints for the route
route( "hello", "main.index" ).constraints( { ... } )
map
- A structure of regex constraint overrides for variable placeholders. The key is the name of the variable, the value is the regex to try to match.Register a route with DELETE restriction. Same as calling the following
route( "/hello", "hello" ).withVerbs( "DELETE" )
pattern
- The pattern to registertarget
- A response closure/lambda or an event string to executeThis is a global route definition terminator. It will grab whatever the fluent API collected and create a route from it.
route( "hello" ).withHandler( "luis" ).withAction( "hello" ).end();
End a with closure and returns itself
group()
function.Get the correct route actions based on only and except lists
initial
- The initial set of route actionsonly
- Limit actions with onlyexcept
- Exclude actions with exceptThis function tries to find a specifc route by incoming name. If you need a route from a module then append the module address: `@moduleName` or prefix it like in run event calls `moduleName:routeName` in order to find the right route.
name
- The name of the routeRegister a route with GET restriction. Same as calling the following
route( "/hello", "hello" ).withVerbs( "GET" )
pattern
- The pattern to registertarget
- A response closure/lambda or an event string to executeA quick snapshot of the router state
Get a module's routes array
module
- The module to getA quick ColdBox4 compatibility wrapper
Get a namespace routes array
namespace
- The namespace to getThis is the new approach to the with
closure approach which has been marked as deprecated.
You can pass any route option via the options
structure and those values will be prefixed against
any routing values done within the body
closure.
group( { pattern="/api", target="api", handler="api" }, function( options ){ route( "/", "main.index" ); route( "/echo", "echo" ); route( "/users/:id" ).withAction( { get : "index", post : "save" } ).toHandler( "users" ); } )
options
- The route options that match routing, look at the addRoute()
methodbody
- The closure or lambda to contain all the routing methods to be grouped with the options data.Add a header to a route
route( "hello", "main.index" ).header( "name", "hello" )
name
- The header namevalue
- The header valueoverwrite
- Overwrite if already definedAppends a collection of header name-values to a pattern
route( "hello" ).headers( { ... } ).to( "main.index" )
map
- The structure of headers to issueoverwrite
- Overwrite the elementsIncludes a routes configuration file as an added import and returns itself after import
location
- The include location of the routes configuration template.Construct a route definition construct
Verifies if an extension is valid in the Router
extension
- The extension to validateAppends a collection of metadata name-values to a pattern
route( "hello" ).meta( { secure : true, perms : [] } ).to( "main.index" )
map
- The structure of metadata to store within the routeoverwrite
- Overwrite the elementsRegister a route with OPTIONS restriction. Same as calling the following
route( "/hello", "hello" ).withVerbs( "OPTIONS" )
pattern
- The pattern to registertarget
- A response closure/lambda or an event string to executeTurn package resolver on/off
route( "hello", "main.index" ).packageResolver( false );
toggle
- The boolean toggleRegister a route with PATHC restriction. Same as calling the following
route( "/hello", "hello" ).withVerbs( "PATHC" )
pattern
- The pattern to registertarget
- A response closure/lambda or an event string to executeRegister a route with POST restriction. Same as calling the following
route( "/hello", "hello" ).withVerbs( "POST" )
pattern
- The pattern to registertarget
- A response closure/lambda or an event string to executeRegister a private request collection name-value pair if the route matches
route( "hello", "main.index" ).prc( "private", true )
name
- The key namevalue
- The valueoverwrite
- Overwrite the valueAppends a collection of name-values to the PRC if the route matches
route( "hello", "main.index" ).prcAppend( { ... } )
map
- The structure to appendoverwrite
- Overwrite elements, default behaviorPrepends the route to the routing table. By default all routes are appended.
route( "hello", "main.index" ).prepend();
Process route optionals
thisRoute
- The route structureprocess a with closure
args
- The arguments to processRegister a route with PUT restriction. Same as calling the following
route( "/hello", "hello" ).withVerbs( "PUT" )
pattern
- The pattern to registertarget
- A response closure/lambda or an event string to executeRegister a request collection name-value pair if the route matches
route( "hello", "main.index" ).rc( "private", true )
name
- The key namevalue
- The valueoverwrite
- Overwrite the valueAppends a collection of name-values to the RC if the route matches
route( "hello", "main.index" ).rcAppend( { ... } )
map
- The structure to appendoverwrite
- Overwrite elements, default behaviorRemove a module's routing table and registration points and return itself
module
- The module to removeRemove a namespace's routing table and registration points and return itself
namespace
- The namespace to removeCreate all RESTful routes for a resource. It will provide automagic mappings between HTTP verbs and URLs to event handlers and actions. By convention the following rules apply - The name of the resource maps to the name of the event handler - The default paremeter name is called `:id` - The available actions are: index, new, create, show, edit, update, delete Example: `resource = photos` Then we will create the following routes: - `/photos` : `GET` -> `photos.index` Display a list of photos - `/photos/new` : `GET` -> `photos.new` Returns an HTML form for creating a new photo - `/photos` : `POST` -> `photos.create` Create a new photo - `/photos/:id` : `GET` -> `photos.show` Display a specific photo - `/photos/:id/edit` : `GET` -> `photos.edit` Return an HTML form for editing a photo - `/photos/:id` : `PUT/PATCH` -> `photos.update` Update a specific photo - `/photos/:id` : `DELETE` -> `photos.delete` Delete a specific photo
resource
- The name of a single resource to maphandler
- The handler for the route. Defaults to the resource name.parameterName
- The name of the id/parameter for the resource. Defaults to `id`.only
- Limit routes created with only this list or array of actions, e.g. "index,show"except
- Exclude routes with an except list or array of actions, e.g. "show"module
- If passed, the module these resources will be attached to.namespace
- If passed, the namespace these resources will be attached to.pattern
- If passed, the actual URL pattern to use, else it defaults to `/#arguments.resource#` the name of the resource.meta
- A struct of metadata to store with ALL the routes created from this resourceInitiate a new route registration. Please note that you must finalize the registration by calling a terminator fluently. Unless, you pass in a target which can be a response closure/lambda or an event string.
// with terminator route( "/home" ).to( "main.index" ) // with inline lambda route( "/home", function( event, rc, prc ){ return "hello"; } ) // with inline event route( "/home", "main.index" ) // with inline event + name route( "/home", "main.index", "home" )
pattern
- The pattern to registertarget
- A response closure/lambda or an event string to executename
- The name of the route, defaults to the the patternbaseURL
cachebox
controller
enabled
extensionDetection
flash
fullRewrites
log
logBox
looseMatching
moduleRoutingTable
multiDomainDiscovery
namespaceRoutingTable
routes
thisModule
thisRoute
throwOnInvalidExtension
validExtensions
wirebox
withClosure
This method is called by the Routing Services to make sure the router is ready for operation. This is ONLY called by the routing services and only ONCE in the Application Life-Cycle
Terminates the route to execute an event
route( "old" ).to( "main.index" ); route( "old" ).to( "main" ); route( "old" ).to( "api:main.index" );
event
- The event to executeTerminates the route to execute a specific action or action struct. Usually the handler has already been defined beforehand.
route( "about/:handler" ).toAction( "index" ) route( "/api/v1/users" ).withHandler( "users" ).toAction( { GET : "index", POST : "save" } )
action
- The action string or the action struct of HTTP verbs matching an actionTerminates the route to execute a specific handler. Usually this will be done if the action is coming via the URL as a `:action` placeholder or you want the default `index` action to execute.
route( "about/:action" ).toHandler( "static" ) route( "users/:action?" ).toHandler( "users" )
handler
- The handler to send this route to for processingTerminate the route to be the entry point for module routing
route( "/api/v1" ).toModuleRouting( "API" );
module
- The module to send the route toTerminate the route to be the entry point for namespace routing
route( "/api/v1" ).toNamespaceRouting( "API" );
namespace
- The namespace to send the route toRedirects to a route or full HTTP URL if the pattern matched
route( "old" ).toRedirect( "/api/new" ); route( "old" ).toRedirect( "/api/new", 302 ); route( "old" ).toRedirect( "https://www.ortussolutions.com"); route( "/users/:id" ).toRedirect( function( route, params, event ){ return "/api/users/#params.id#"; })
target
- The target URIstatusCode
- The statusCode to use, defaults to 301Terminates the route to execute a response closure with optional status codes and texts
route( "old" ).toResponse( ( event, rc, prc ) => { ... return "html/data" } );
body
- The body of the response a lambda or closurestatusCode
- The status code to use, defaults to 200Send a route to a view/layout combo
route( "hello", "main.index" ).toView( "hello" ); route( "hello", "main.index" ).toView( view="hello", layout="rest" ); route( "hello", "main.index" ).toView( view="hello", noLayout=true );
view
- The view to renderlayout
- The layout to use or default onenoLayout
- Use only the view or attach the layoutviewModule
- The module the view comes fromlayoutModule
- The module the layout comes fromTurns on/off the value pair translator from extra metadata in a URL
route( "hello", "main.index" ).valuePairTranslation( false );
toggle
- The boolean toggleStarts a with closure, where all arguments will be prefixed for the next concatenated addRoute() methods until an endWith() is called
group()
function.pattern
- The pattern to match against the URL.handler
- The handler to execute if pattern matched.action
- The action in a handler to execute if a pattern is matched. This can also be a structure based on the HTTP method(GET,POST,PUT,DELETE). ex: {GET:'show', PUT:'update', DELETE:'delete', POST:'save'}packageResolverExempt
- If this is set to true, then the interceptor will not try to do handler package resolving. Else a package will always be resolved. Only works if :handler is in a patternmatchVariables
- A string of name-value pair variables to add to the request collection when this pattern matches. This is a comma delimited list. Ex: spaceFound=true,missingAction=onTestview
- The view to dispatch if pattern matches. No event will be fired, so handler,action will be ignored.viewNoLayout
- If view is chosen, then you can choose to override and not display a layout with the view. Else the view renders in the assigned layout.valuePairTranslation
- Activate convention name value pair translations or not. Turned on by defaultconstraints
- A structure of regex constraint overrides for variable placeholders. The key is the name of the variable, the value is the regex to try to match.module
- The module to add this route tomoduleRouting
- Called internally by addModuleRoutes to add a module routing route.namespace
- The namespace to add this route tonamespaceRouting
- Called internally by addNamespaceRoutes to add a namespaced routing route.ssl
- Makes the route an SSL only route if true, else it can be anything. If an ssl only route is hit without ssl, the interceptor will redirect to it via sslappend
- Whether the route should be appended or pre-pended to the array. By default we append to the end of the arraydomain
- The domain to match, including wildcardsRegisters a pattern into a specific action for execution. The action string can be a single action or a struct of
HTTP Verb to actions map. Usually this is called to keep track of actions throughout a route definition and then follow
it with a handler terminator or the global terminator: `end()`
Please see examples below:
route( "api/user" ).\withAction( { get : "index", delete : "delete" } ).toHandler( "User" ); route( "api/user/details" ).withAction( "details" ).toHandler( "User" ); route( "api/:handler" ).withAction( "index" ).end();
action
- The action string or the action struct of HTTP verbs matching an actionRegisters a closure/lambda that will be called once the route matches to verify if we can proceed and execute its terminators. The closure/lambda must return boolean
route( "hello", "main.index" ).withCondition( () => return false )
condition
- closure or lambdaRegisters a pattern that must exist under a domain pattern
route( "hello", "main.index" ).withDomain( ":username.forgebox.dev" )
domain
- The domain constructRegisters a pattern into a specific handler for execution. The handler string can include dot notations for folder paths or even
a module `:` designator. Usually this is called if you want to delegate a route to a specific action terminator `toAction()`.
This action can be a single action or a struct of HTTP Verbs to action maps. Please note that this is NOT the same as using
the `toHandler()` terminator, which terminates the route addition to a specific handler.
Please see examples below:
route( "api/user" ).withHandler( "User" ).toAction( { get : "index", delete : "delete" } ); route( "api/user/details" ).withHandler( "User" ).toAction( "details" );
handler
- The handler syntaxRegisters a pattern into a specific module routing table
route( "hello", "main.index" ).withModule( "explorer" )
name
- The module nameRegisters a pattern into a specific Namespace routing table
route( "hello", "main.index" ).withNamespace( "myAPI" )
name
- The namespace nameForces SSL on the route
route( "hello", "main.index" ).withSSL()
Restricts the route to specific HTTP Verbs. Just pass a list of allowed verbs
route( "hello", "main.index" ).withVerbs( "GET,POST,PUT" );
verbs
- The list of HTTP Verbs