UNPKG

@loopback/docs

Version:

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

52 lines (36 loc) 1.59 kB
--- lang: en title: 'API docs: rest.restserver.route' 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.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.md) ## RestServer.route() method Register a new Controller-based route. <b>Signature:</b> ```typescript route<I>(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](./rest.controllerclass.md)<!-- -->&lt;I&gt; | Controller constructor | | controllerFactory | [ControllerFactory](./rest.controllerfactory.md)<!-- -->&lt;I&gt; | A factory function to create controller instance | | methodName | string | The name of the controller method | <b>Returns:</b> [Binding](./context.binding.md) ## Example ```ts class MyController { greet(name: string) { return `hello ${name}`; } } app.route('get', '/greet', operationSpec, MyController, 'greet'); ```