TramwayJS

Route

A configuration object defining how a route is set up.

Definition

Create

tramway create:route ProductController getOne /products --methods get --args id --create-controller

Locations

  • Implementation: src/config/parameters/global/routes.js
  • Dependency Injection: src/config/parameters/global/routes.js

Specs

AttributeExpected ValuesDefault ValuesNotes
pathUnparameterized path string"/"If no path is specified, the router will default to root.
controllerstringundefinedThe key of the Controller as configured in dependency injection.
actionstringundefinedThe name of the Controller method dedicated to handling the route. If not a restful route and no action is specified, the app will break
restfulbooleanundefinedIf the controller is a restful controller - note that action attribute will be ignored
methods["get", "post", "put", "delete", "all"]["get"]Indicates which http methods get assigned the controller. Restful routes will ignore this setting as it is automatically bound by implenentation
argumentsstring[]""An optional ordered array of arguments to add to the path. ["id", "name"] equates to "/:id/:name"
policystringundefinedThe key of the Policy to apply to the route. Ignored if unpresent, applies a policy or authentication strategy before allowing the router to proceed to the controller when a request is made

Example

const routeValues = [
{
"controller": "controller.main",
"action": "index",
"methods": ["get"]
},
{
"controller": "controller.product",
"action": "getOne",
"path": "products",
"methods": ["get"],
"arguments": ["id"],
"links": [
{"label": "accessories", "link": "accessories"},
]
},
{
"controller": "controller.product",
"action": "create",
"path": "products",
"methods": ["post"]
},
{
"controller": "controller.product",
"action": "update",
"path": "products",
"methods": ["patch"],
"arguments": ["id"]
},
{
"controller": "controller.product",
"action": "replace",
"path": "products",
"methods": ["put"],
"arguments": ["id"]
},
{
"controller": "controller.product",
"action": "delete",
"path": "products",
"methods": ["delete"],
"arguments": ["id"]
},
{
"controller": "controller.accessory",
"path": "products/:productId/accessories",
"restful": true,
"policy": "policy.product",
},
];
export default routeValues;