coldbox.system.web.routing

Class Router

lucee.Component
    extended by coldbox.system.FrameworkSupertype
      extended by coldbox.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

Class Attributes:
  • threadsafe
  •  
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
    Property Summary
    type property default serializable required
    string baseURL
          Base routing URL.

    • access = public
    • returntype = any
    true false
    any controller
          ColdBox Controller.

    • access = public
    • returntype = any
    true false
    boolean enabled
          Flag to enable/disable routing.

    • access = public
    • returntype = any
    true true false
    boolean extensionDetection
          Detect extensions flag, so it can place a 'format' variable on the rc.

    • access = public
    • returntype = any
    true true false
    boolean fullRewrites
          This flag denotes if full URL rewrites are enabled or not.

    • access = public
    • returntype = any
    false true false
    boolean looseMatching
          Loose matching flag for regex matches.

    • access = public
    • returntype = any
    false true false
    struct moduleRoutingTable
          Modules Routing Table.

    • access = public
    • returntype = any
    true false
    struct namespaceRoutingTable
          Namespace routing tables.

    • access = public
    • returntype = any
    true false
    array routes
          The routing table.

    • access = public
    • returntype = any
    true false
    string thisModule
          Fluent route construct for modules.

    • access = public
    • returntype = any
    true false
    struct thisRoute
          Fluent route construct.

    • access = public
    • returntype = any
    true false
    boolean throwOnInvalidExtension
          Throw an exception when extension detection is invalid or not.

    • access = public
    • returntype = any
    false true false
    boolean uniqueURLS
          Flag to enable unique or not URLs.

    • access = public
    • returntype = any
    false true false
    string validExtensions
          Initialize the valid extensions to detect.

    • access = public
    • returntype = any
    json,jsont,xml,cfm,cfml,html,htm,rss,pdf true false
    struct withClosure
          Fluent route construct for with routing.

    • access = public
    • returntype = any
    true false
    Constructor Summary
    init(any controller)
          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'], [string statusText=''], [any condition=''], [string name=''], [string domain=''], [string redirect=''], [string event=''], [string verbs=''], [string layout=''], [struct headers='[runtime expression]'], [struct rc='[runtime expression]'], [struct prc='[runtime expression]'], [string viewModule=''], [string layoutModule=''])
         Adds a route to dispatch and returns itself.
    any append()
         Appends the route to the routing table.
    any as(any name)
         Registers the route as a named route.
    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.
    any get(any pattern, [any target])
         Register a route with GET restriction.
    any getAutoReload()
    any getBaseURL()
    string getEnabled()
    string getExtensionDetection()
    any getFullRewrites()
    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.
    array getNamespaceRoutes(any namespace)
         Get a namespace routes array.
    string getNamespaceRoutingTable()
    string getRoutes()
    string getThisModule()
    string getThisRoute()
    string getThrowOnInvalidExtension()
    any getUniqueURLS()
    string getValidExtensions()
    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 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='[runtime expression]'], [any parameterName='id'], [any only='[runtime expression]'], [any except='[runtime expression]'], [string module=''], [string namespace=''])
         Create all RESTful routes for a resource.
    any route(any pattern, [any target], [any name=''])
         Initiate a new route registration.
    any setAutoReload()
    any setBaseURL([string baseURL])
    any setEnabled(boolean enabled)
    any setExtensionDetection(boolean extensionDetection)
    any setFullRewrites([boolean target])
    any setLooseMatching(boolean looseMatching)
    any setModuleRoutingTable(struct moduleRoutingTable)
    any setNamespaceRoutingTable(struct namespaceRoutingTable)
    any setRoutes(array routes)
    any setThisModule(string thisModule)
    any setThisRoute(struct thisRoute)
    any setThrowOnInvalidExtension(boolean throwOnInvalidExtension)
    any setUniqueURLS([boolean uniqueURLS])
    any setValidExtensions(any extensions)
    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 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'], [any statusText='Ok'])
         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 valuePairTranslator(boolean toggle)
         Turns on/off the value pair translator from extra metdata 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 coldbox.system.FrameworkSupertype
    addAsset, announceInterception, getCache, getController, getInstance, getInterceptor, getModel, getModuleConfig, getModuleSettings, getMyPlugin, getPlugin, getRenderer, getRequestCollection, getRequestContext, getSetting, getSettingStructure, includeUDF, loadApplicationHelpers, locateDirectoryPath, locateFilePath, persistVariables, populateModel, relocate, renderExternalView, renderLayout, renderView, runEvent, setController, setNextEvent, setSetting, settingExists
     
    Methods inherited from class lucee.Component
    None

    Constructor Detail

    init

    public init(any controller)

    Constructor

    Parameters:
    controller - The ColdBox controller linkage

    Property Detail

    baseURL

    property string baseURL

    Base routing URL

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    controller

    property any controller

    ColdBox Controller

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    enabled

    property boolean enabled = [true]

    Flag to enable/disable routing

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    extensionDetection

    property boolean extensionDetection = [true]

    Detect extensions flag, so it can place a 'format' variable on the rc

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    fullRewrites

    property boolean fullRewrites = [false]

    This flag denotes if full URL rewrites are enabled or not. Meaning if the `index.cfm` is in the path of the rewriter or not. The default value is **false**.

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    looseMatching

    property boolean looseMatching = [false]

    Loose matching flag for regex matches

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    moduleRoutingTable

    property struct moduleRoutingTable

    Modules Routing Table

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    namespaceRoutingTable

    property struct namespaceRoutingTable

    Namespace routing tables

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    routes

    property array routes

    The routing table

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    thisModule

    property string thisModule

    Fluent route construct for modules

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    thisRoute

    property struct thisRoute

    Fluent route construct

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    throwOnInvalidExtension

    property boolean throwOnInvalidExtension = [false]

    Throw an exception when extension detection is invalid or not

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    uniqueURLS

    property boolean uniqueURLS = [false]

    Flag to enable unique or not URLs

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    validExtensions

    property string validExtensions = [json,jsont,xml,cfm,cfml,html,htm,rss,pdf]

    Initialize the valid extensions to detect

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    withClosure

    property struct withClosure

    Fluent route construct for with routing

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    Method Detail

    addModuleRoutes

    public any addModuleRoutes(any pattern, any module, [boolean append='true'])

    Register modules routes in the specified position in the main routing table, and returns itself

    Parameters:
    pattern - The pattern to match against the URL
    module - The module to load routes for
    append - 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 array
    Returns:
    Router

    addNamespace

    public any addNamespace(any pattern, any namespace, [boolean append='true'])

    Register a namespace in the specified position in the main routing table, and returns itself

    Parameters:
    pattern - The pattern to match against the URL.
    namespace - The name of the namespace to register
    append - Whether the route should be appended or pre-pended to the array. By default we append to the end of the array
    Returns:
    Router

    addRoute

    public 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'], [string statusText=''], [any condition=''], [string name=''], [string domain=''], [string redirect=''], [string event=''], [string verbs=''], [string layout=''], [struct headers='[runtime expression]'], [struct rc='[runtime expression]'], [struct prc='[runtime expression]'], [string viewModule=''], [string layoutModule=''])

    Adds a route to dispatch and returns itself.

    Parameters:
    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 pattern
    matchVariables - 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 delimmitted list. Ex: spaceFound=true,missingAction=onTest
    view - The view to dispatch if pattern matches. No event will be fired, so handler,action will be ignored.
    viewNoLayout - If view is choosen, 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 default
    constraints - 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 to
    moduleRouting - Called internally by addModuleRoutes to add a module routing route.
    namespace - The namespace to add this route to
    namespaceRouting - 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 ssl
    append - Whether the route should be appended or pre-pended to the array. By default we append to the end of the array
    response - 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.
    statusText - Explains the HTTP status code sent 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 route
    domain - The domain to match, including wildcards
    redirect - 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 matches
    verbs - The allowed HTTP Verbs for the route
    layout - The view layout to use
    headers - The HTTP headers to attach to the response if route matches
    rc - The RC name value pairs to attach if the reponse matches
    prc - The PRC name value pairs to attach if the reponse matches
    viewModule - The module the view belongs to
    layoutModule - The module the layout belongs to
    Returns:
    SES

    append

    public any append()

    Appends the route to the routing table. By default all routes are appended.

    route( "hello", "main.index" ).append();
    


    as

    public any as(any name)

    Registers the route as a named route

    route( "hello", "main.index" ).as( "main" )
    

    Parameters:
    name - The name to use for the route

    configure

    public any configure()

    This method is to be implemented by the application router you create. This is where you will define all your routing.


    constraints

    public any constraints(any map)

    Register a struct of constraints for the route

    route( "hello", "main.index" ).constraints( { ... } )
    

    Parameters:
    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.

    delete

    public any delete(any pattern, [any target])

    Register a route with DELETE restriction. Same as calling the following

    route( "/hello", "hello" ).withVerbs( "DELETE" )
    

    Parameters:
    pattern - The pattern to register
    target - A response closure/lambda or an event string to execute

    end

    public any end()

    This 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();
    


    endWith Deprecated

    public any endWith()

    End a with closure and returns itself

    Deprecated:
    This has been deprecated in favor of the group() function.
    Returns:
    Router

    filterRouteActions

    private struct filterRouteActions(struct initial, [array only='[runtime expression]'], [array except='[runtime expression]'])

    Get the correct route actions based on only and except lists

    Parameters:
    initial - The initial set of route actions
    only - Limit actions with only
    except - Exclude actions with except

    get

    public any get(any pattern, [any target])

    Register a route with GET restriction. Same as calling the following

    route( "/hello", "hello" ).withVerbs( "GET" )
    

    Parameters:
    pattern - The pattern to register
    target - A response closure/lambda or an event string to execute

    getAutoReload

    public any getAutoReload()


    getBaseURL

    public any getBaseURL()


    getEnabled

    public string getEnabled()


    getExtensionDetection

    public string getExtensionDetection()


    getFullRewrites

    public any getFullRewrites()


    getLooseMatching

    public string getLooseMatching()


    getMemento

    public struct getMemento()

    A quick snapshot of the router state


    getModuleRoutes

    public array getModuleRoutes(any module)

    Get a module's routes array

    Parameters:
    module - The module to get

    getModuleRoutingTable

    public string getModuleRoutingTable()


    getModulesRoutingTable Deprecated

    public struct getModulesRoutingTable()

    A quick ColdBox4 compatibility wrapper

    Deprecated:
    Please use `getModuleRoutingTable()` instead.

    getNamespaceRoutes

    public array getNamespaceRoutes(any namespace)

    Get a namespace routes array

    Parameters:
    namespace - The namespace to get

    getNamespaceRoutingTable

    public string getNamespaceRoutingTable()


    getRoutes

    public string getRoutes()


    getThisModule

    public string getThisModule()


    getThisRoute

    public string getThisRoute()


    getThrowOnInvalidExtension

    public string getThrowOnInvalidExtension()


    getUniqueURLS

    public any getUniqueURLS()


    getValidExtensions

    public string getValidExtensions()


    getWithClosure

    public string getWithClosure()


    group

    public any group([struct options='[runtime expression]'], [any body])

    This 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 withing 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" );
    } )
    

    Parameters:
    options - The route options that match routing, look at the addRoute() method
    body - The closure or lambda to contain all the routing methods to be grouped with the options data.

    header

    public any header(any name, any value, [boolean overwrite='true'])

    Add a header to a route

    route( "hello", "main.index" ).header( "name", "hello" )
    

    Parameters:
    name - The header name
    value - The header value
    overwrite - Overwrite if already defined

    headers

    public any headers(any map, [boolean overwrite='true'])

    Appends a collection of header name-values to a pattern

    route( "hello", "main.index" ).headers( { ... } )
    

    Parameters:
    map - The structure of headers to issue
    overwrite - Overwrite the elements

    includeRoutes Deprecated

    public any includeRoutes(any location)

    Includes a routes configuration file as an added import and returns itself after import

    Deprecated:
    Please use the Routes.cfc approach instead
    Parameters:
    location - The include location of the routes configuration template. Do not add '.cfm'
    Returns:
    Router

    initRouteDefinition

    private struct initRouteDefinition()

    Construct a route definition construct


    isValidExtension

    public boolean isValidExtension(any extension)

    Verifies if an extension is valid in the Router

    Parameters:
    extension - The extension to validate

    options

    public any options(any pattern, [any target])

    Register a route with OPTIONS restriction. Same as calling the following

    route( "/hello", "hello" ).withVerbs( "OPTIONS" )
    

    Parameters:
    pattern - The pattern to register
    target - A response closure/lambda or an event string to execute

    packageResolver

    public any packageResolver(boolean toggle)

    Turn package resolver on/off

    route( "hello", "main.index" ).packageResolver( false );
    

    Parameters:
    toggle - The boolean toggle

    patch

    public any patch(any pattern, [any target])

    Register a route with PATHC restriction. Same as calling the following

    route( "/hello", "hello" ).withVerbs( "PATHC" )
    

    Parameters:
    pattern - The pattern to register
    target - A response closure/lambda or an event string to execute

    post

    public any post(any pattern, [any target])

    Register a route with POST restriction. Same as calling the following

    route( "/hello", "hello" ).withVerbs( "POST" )
    

    Parameters:
    pattern - The pattern to register
    target - A response closure/lambda or an event string to execute

    prc

    public any prc(any name, any value, [boolean overwrite='true'])

    Register a private request collection name-value pair if the route matches

    route( "hello", "main.index" ).prc( "private", true )
    

    Parameters:
    name - The key name
    value - The value
    overwrite - Overwrite the value

    prcAppend

    public any prcAppend(any map, [boolean overwrite='true'])

    Appends a collection of name-values to the PRC if the route matches

    route( "hello", "main.index" ).prcAppend( { ... } )
    

    Parameters:
    map - The structure to append
    overwrite - Overwrite elements, default behavior

    prepend

    public any prepend()

    Prepends the route to the routing table. By default all routes are appended.

    route( "hello", "main.index" ).prepend();
    


    processRouteOptionals

    private any processRouteOptionals(struct thisRoute)

    Process route optionals

    Parameters:
    thisRoute - The route structure

    processWith

    public any processWith(any args)

    process a with closure

    Parameters:
    args - The arugments to process
    Returns:
    Router

    put

    public any put(any pattern, [any target])

    Register a route with PUT restriction. Same as calling the following

    route( "/hello", "hello" ).withVerbs( "PUT" )
    

    Parameters:
    pattern - The pattern to register
    target - A response closure/lambda or an event string to execute

    rc

    public any rc(any name, any value, [boolean overwrite='true'])

    Register a request collection name-value pair if the route matches

    route( "hello", "main.index" ).rc( "private", true )
    

    Parameters:
    name - The key name
    value - The value
    overwrite - Overwrite the value

    rcAppend

    public any rcAppend(any map, [boolean overwrite='true'])

    Appends a collection of name-values to the RC if the route matches

    route( "hello", "main.index" ).rcAppend( { ... } )
    

    Parameters:
    map - The structure to append
    overwrite - Overwrite elements, default behavior

    removeModuleRoutes

    public any removeModuleRoutes(any module)

    Remove a module's routing table and registration points and return itself

    Parameters:
    module - The module to remove
    Returns:
    Router

    removeNamespaceRoutes

    public any removeNamespaceRoutes(any namespace)

    Remove a namespace's routing table and registration points and return itself

    Parameters:
    namespace - The namespace to remove
    Returns:
    Router

    resources

    public any resources(any resource, [any handler='[runtime expression]'], [any parameterName='id'], [any only='[runtime expression]'], [any except='[runtime expression]'], [string module=''], [string namespace=''])

    Create all RESTful routes for a resource. It will provide automagic mappings between HTTP verbs and URLs to event handlers and actions. By convention, the name of the resource maps to the name of the event handler. 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` : `POST/PUT/PATCH` -> `photos.update` Update a specific photo - `/photos/:id` : `DELETE` -> `photos.delete` Delete a specific photo

    Parameters:
    resource - The name of a single resource or a list of resources or an array of resources
    handler - 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.

    route

    public any route(any pattern, [any target], [any name=''])

    Initiate 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 reponse 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" )
    

    Parameters:
    pattern - The pattern to register
    target - A response closure/lambda or an event string to execute
    name - The name of the route

    setAutoReload

    public any setAutoReload()


    setBaseURL

    public any setBaseURL([string baseURL])

    Parameters:
    baseURL

    setEnabled

    public any setEnabled(boolean enabled)

    Parameters:
    enabled

    setExtensionDetection

    public any setExtensionDetection(boolean extensionDetection)

    Parameters:
    extensionDetection

    setFullRewrites

    public any setFullRewrites([boolean target])

    Parameters:
    target

    setLooseMatching

    public any setLooseMatching(boolean looseMatching)

    Parameters:
    looseMatching

    setModuleRoutingTable

    public any setModuleRoutingTable(struct moduleRoutingTable)

    Parameters:
    moduleRoutingTable

    setNamespaceRoutingTable

    public any setNamespaceRoutingTable(struct namespaceRoutingTable)

    Parameters:
    namespaceRoutingTable

    setRoutes

    public any setRoutes(array routes)

    Parameters:
    routes

    setThisModule

    public any setThisModule(string thisModule)

    Parameters:
    thisModule

    setThisRoute

    public any setThisRoute(struct thisRoute)

    Parameters:
    thisRoute

    setThrowOnInvalidExtension

    public any setThrowOnInvalidExtension(boolean throwOnInvalidExtension)

    Parameters:
    throwOnInvalidExtension

    setUniqueURLS

    public any setUniqueURLS([boolean uniqueURLS])

    Parameters:
    uniqueURLS

    setValidExtensions

    public any setValidExtensions(any extensions)

    Parameters:
    extensions

    setWithClosure

    public any setWithClosure(struct withClosure)

    Parameters:
    withClosure

    startup

    public any startup()

    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.


    to

    public any to(any event)

    Terminates the route to execute an event

    route( "old" ).to( "main.index" );
    route( "old" ).to( "main" );
    route( "old" ).to( "api:main.index" );
    

    Parameters:
    event

    toHandler

    public any toHandler(any handler)

    Terminates 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" )
    

    Parameters:
    handler

    toModuleRouting

    public any toModuleRouting(any module)

    Terminate the route to be the entry point for module routing

    route( "/api/v1" ).toModuleRouting( "API" );
    

    Parameters:
    module

    toNamespaceRouting

    public any toNamespaceRouting(any namespace)

    Terminate the route to be the entry point for namespace routing

    route( "/api/v1" ).toNamespaceRouting( "API" );
    

    Parameters:
    namespace

    toRedirect

    public any toRedirect(any target, [any statusCode='301'])

    Redirects 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");
    

    Parameters:
    target
    statusCode

    toResponse

    public any toResponse(any body, [numeric statusCode='200'], [any statusText='Ok'])

    Terminates the route to execute a response closure with optional status codes and texts

    route( "old" ).toResponse( ( event, rc, prc ) => {
    ...
    return "html/data"
    } );
    

    Parameters:
    body
    statusCode
    statusText

    toView

    public any toView(any view, [any layout=''], [boolean noLayout='false'], [any viewModule=''], [any layoutModule=''])

    Send 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 );
    

    Parameters:
    view
    layout
    noLayout
    viewModule
    layoutModule

    valuePairTranslator

    public any valuePairTranslator(boolean toggle)

    Turns on/off the value pair translator from extra metdata in a URL

    route( "hello", "main.index" ).valuePairTranslator( false );
    

    Parameters:
    toggle - The boolean toggle

    with Deprecated

    public 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

    Deprecated:
    This has been deprecated in favor of the group() function.
    Parameters:
    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 pattern
    matchVariables - A string of name-value pair variables to add to the request collection when this pattern matches. This is a comma delimmitted list. Ex: spaceFound=true,missingAction=onTest
    view - The view to dispatch if pattern matches. No event will be fired, so handler,action will be ignored.
    viewNoLayout - If view is choosen, 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 default
    constraints - 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 to
    moduleRouting - Called internally by addModuleRoutes to add a module routing route.
    namespace - The namespace to add this route to
    namespaceRouting - 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 ssl
    append - Whether the route should be appended or pre-pended to the array. By default we append to the end of the array
    domain - The domain to match, including wildcards
    Returns:
    Router

    withAction

    public any withAction(any action)

    Registers 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();
    

    Parameters:
    action

    withCondition

    public 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. The closure/lambda must return boolean

    route( "hello", "main.index" ).withCondition( () => return false )
    

    Parameters:
    condition - closure or lambda

    withDomain

    public any withDomain(any domain)

    Registers a pattern that must exist under a domain pattern

    route( "hello", "main.index" ).withDomain( ":username.forgebox.dev" )
    

    Parameters:
    domain - The domain construct

    withHandler

    public any withHandler(any handler)

    Registers 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" );
    

    Parameters:
    handler - The handler syntax

    withModule

    public any withModule(any name)

    Registers a pattern into a specific module routing table

    route( "hello", "main.index" ).withModule( "explorer" )
    

    Parameters:
    name - The module name

    withNamespace

    public any withNamespace(any name)

    Registers a pattern into a specific Namespace routing table

    route( "hello", "main.index" ).withNamespace( "myAPI" )
    

    Parameters:
    name - The namespace name

    withSSL

    public any withSSL()

    Forces SSL on the route

    route( "hello", "main.index" ).withSSL()
    


    withVerbs

    public any withVerbs(any verbs)

    Restricts the route to specific HTTP Verbs. Just pass a list of allowed verbs

    route( "hello", "main.index" ).withVerbs( "GET,POST,PUT" );
    

    Parameters:
    verbs - The list of HTTP Verbs