Page Contents

Home > @loopback/rest > RestApplication > route

RestApplication.route() method

Register a new route invoking a handler function.

Signature:

route(verb: string, path: string, spec: OperationObject, handler: Function): 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)

handler

Function

The function to invoke with the request parameters described in the spec.

Returns:

Binding

Example

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