Page Contents

Home > @loopback/rest > RestApplication > route

RestApplication.route() method

Register a new Controller-based route.

Signature:

route<T extends object>(verb: string, path: string, spec: OperationObject, controllerCtor: ControllerClass<T>, controllerFactory: ControllerFactory<T>, 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<T>

Controller constructor

controllerFactory

ControllerFactory<T>

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');