Skip to content
Youmy001 edited this page Feb 4, 2018 · 13 revisions

As of release v1.0, it is possible to use either XML or JSON to write routes, JSON being the new default. On older installations of APIne, when migrating to v1.0 the content of the older routes.xml file will be automatically exported to a JSON file and a new entry in the configuration file will be written. Routes are used by the web app but not by the API.

As of release v1.1, the use of XML route configuration is deprecated.

Configuration option

It is possible to use either XML or JSON in APIne v1.0. By default, the framework will attempt to use JSON and will automatically export the content XML file if the JSON file is not found. To change that behavior, you can add or modify the route_format in the runtime section of the configuration and set it to either json or xml.

JSON

Routes are written in the routes.json file located at the rout of the project's directory.

Attributes

  • args : true or false Mandatory Does the router has to look for arguments in the query string;
  • argsnum : integer Optional How many arguments are there in the query string;
  • controller : Mandatory Destination controller name;
  • action : Mandatory Destination action name;

Example

"/user/([0-9]+)" : {
    "GET" : {
        "args": true,
        "controller": "user",
        "action": "profile"
    },
    "POST" : {
        "args": true,
        "controller": "user",
        "action": "save"
    }
}

XML Routes

Routes are written in the routes.xml file located at the root of the project's directory. A route is represented by a <route> tag and has three childs nodes <request>, <controller> and <action>.

Attributes

  • args="true|false" : Mandatory Does the router has to look for arguments in the query string;
  • argsnum=number : Optional How many arguments are there in the query string;
  • method="GET|POST|DELETE|PUT" : Mandatory Which request method does this route accept.

Child nodes

  • <request> : Mandatory A regular expression whose the router matches with the query string
  • <controller> : Mandatory Destination controller name
  • <action> : Mandatory Destination action name

Example

<route args="true" argsnum=1 method="GET">
    <request>/user/([0-9]+)</request>
    <controller>user</controller>
    <action>profile</action>
</route>

This route refers to a request through the GET method with one argument in the query string and redirects to the profile action in the user controller.

Clone this wiki locally