Resource and routes
Resources are operations that are grouped in a namespace. You declare such a namespace by adding the @route
decorator to provide the path to that resource:
To define an operation on this resource, you need to provide the HTTP verb for the route using the @get
, @head
@post
, @put
, @patch
, or @delete
decorators. If an HTTP method decorator is not specified then the default is post if there is a body and get otherwise. Lets add an operation to our Pets
resource:
If @route
is applied to an interface, that route is not “portable”. It will be applied to that interface but will not carry over if another interface extends it.
Automatic route generation
Instead of manually specifying routes using the @route
decorator, you automatically generate routes from operation parameters by applying the @autoRoute
decorator to an operation or interface containing operations.
For this to work, an operation’s path parameters (those marked with @path
) must also be marked with
the @segment
decorator to define the preceding path segment.
This is especially useful when reusing common parameter sets defined as model types.
For example:
This will result in the following route for both operations
If @autoRoute
is applied to an interface, it is not “portable”. It will be applied to that interface but will not carry over if another interface extends it.
Customizing Automatic Route Generation
Instead of manually specifying routes using the @route
decorator, you automatically generate
routes from operation parameters by applying the @autoRoute
decorator to an operation, namespace,
or interface containing operations.