Define a route (Controller)
Setting up a route for your application
Define a route
To define a the root of your route use the @Controller("/rootPath")
decorator.
For example for "/dashboard/find"
and "/dashboard/update"
, the root of the route is dashboard.
To define sub path ("/find"
or "/update"
), use @HttpGet
, @HttpPut
, @HttpDelete
, @HttpPost
and the route as parameter.
Handling the request
SugoiJS uses inversify-express-utils decorators and re-export them.
For handling the request there are some decorator which can be us as the functions' arguments:
@RequestParam(paramName?:string) param
- will return the parameters\ parameter under this property, if none found, null will be returned.@QueryParam(paramName?:string) qParam
- will return the query parameters\ parameter under this property, if none found, null will be returned.@RequestBody() body
- The body of the request@Cookies(cookieName:string) cookie
- The cookie which fits to the name, if none found, null will be returned.@RequestHeaders(headerName:string)
- The header which fits to the name, if none found, null will be returned.@Response()
- The response object.@Request()
- The request object.
Handling the response
The response of the request will be whatever returned from the function, in case of thrown exception, the exception will get into the error handler who set on the bootstrapping level.
Further information can be found under Response handling
section
Example
Further information can be found on Inversify-express-utils documentation
Last updated