Creating HTTP routes and endpoints in Orionjs
@Routes()
and @Route()
decorators. This approach allows you to organize your API endpoints in controller classes with dependency injection support.
@Routes()
that contains methods decorated with @Route()
to define individual endpoints:
createRoute()
function accepts the following options:
Option | Type | Description |
---|---|---|
path | string | URL path pattern for the route (supports Express path parameters) |
method | 'get' | 'post' | 'put' | 'delete' | 'all' | HTTP method to handle |
bodyParams | Object | Schema | Schema for validating request body |
queryParams | Object | Schema | Schema for validating query parameters |
returns | Object | Schema | Schema for validating response body |
middlewares | Array<RequestHandler> | Express middlewares to apply to this route |
resolve | Function | Function that handles the request and returns a response |
app | express.Application | Optional custom Express app instance |
resolve
function) receive the request object and any middleware-injected properties:
req
: Express Request object with params, query, and bodyqueryParams
option:
bodyParams
option:
multer
middleware:
middlewares
option:
@Inject(() => Service)
for clean service integration.