UNPKG

@loopback/docs

Version:

Documentation files rendered at [https://loopback.io](https://loopback.io)

123 lines (62 loc) 1.72 kB
--- lang: en title: 'API docs: rest.restserver.route_1' keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI sidebar: lb4_sidebar editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/rest permalink: /doc/en/lb4/apidocs.rest.restserver.route_1.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/rest](./rest.md) &gt; [RestServer](./rest.restserver.md) &gt; [route](./rest.restserver.route_1.md) ## RestServer.route() method Register a new route invoking a handler function. **Signature:** ```typescript route(verb: string, path: string, spec: OperationObject, handler: Function): Binding; ``` ## Parameters <table><thead><tr><th> Parameter </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td markdown="1"> verb </td><td markdown="1"> string </td><td markdown="1"> HTTP verb of the endpoint </td></tr> <tr><td markdown="1"> path </td><td markdown="1"> string </td><td markdown="1"> URL path of the endpoint </td></tr> <tr><td markdown="1"> spec </td><td markdown="1"> OperationObject </td><td markdown="1"> The OpenAPI spec describing the endpoint (operation) </td></tr> <tr><td markdown="1"> handler </td><td markdown="1"> Function </td><td markdown="1"> The function to invoke with the request parameters described in the spec. </td></tr> </tbody></table> **Returns:** [Binding](./context.binding.md) ## Example ```ts function greet(name: string) { return `hello ${name}`; } app.route('get', '/', operationSpec, greet); ```