Page Contents

Home > @loopback/rest > RestServer > route

RestServer.route() method

Register a new Controller-based route.

Signature:

route<I extends object>(verb: string, path: string, spec: OperationObject, controllerCtor: ControllerClass<I>, controllerFactory: ControllerFactory<I>, methodName: string): Binding;

Parameters

Parameter Type Description
verb string HTTP verb of the endpoint
path string URL path of the endpoint
spec OperationObject The OpenAPI spec describing the endpoint (operation)
controllerCtor ControllerClass<I> Controller constructor
controllerFactory ControllerFactory<I> A factory function to create controller instance
methodName string The name of the controller method

Returns:

Binding

Example

class MyController {
  greet(name: string) {
    return `hello ${name}`;
  }
}
app.route('get', '/greet', operationSpec, MyController, 'greet');