UNPKG

@loopback/docs

Version:

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

397 lines (177 loc) 6.53 kB
--- lang: en title: 'API docs: rest.restapplication' 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.restapplication.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/rest](./rest.md) &gt; [RestApplication](./rest.restapplication.md) ## RestApplication class An implementation of the Application class that automatically provides an instance of a REST server. This application class is intended to be a single-server implementation. Any attempt to bind additional servers will throw an error. **Signature:** ```typescript export declare class RestApplication extends Application implements HttpServerLike ``` **Extends:** [Application](./core.application.md) **Implements:** [HttpServerLike](./rest.httpserverlike.md) ## Constructors <table><thead><tr><th> Constructor </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td markdown="1"> [(constructor)(parent)](./rest.restapplication._constructor_.md) </td><td markdown="1"> </td><td markdown="1"> Create a REST application with the given parent context </td></tr> <tr><td markdown="1"> [(constructor)(config, parent)](./rest.restapplication._constructor__1.md) </td><td markdown="1"> </td><td markdown="1"> Create a REST application with the given configuration and parent context </td></tr> </tbody></table> ## Properties <table><thead><tr><th> Property </th><th> Modifiers </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td markdown="1"> [requestHandler](./rest.restapplication.requesthandler.md) </td><td markdown="1"> `readonly` </td><td markdown="1"> [HttpRequestListener](./rest.httprequestlistener.md) </td><td markdown="1"> Handle incoming HTTP(S) request by invoking the corresponding Controller method via the configured Sequence. </td></tr> <tr><td markdown="1"> [restServer](./rest.restapplication.restserver.md) </td><td markdown="1"> `readonly` </td><td markdown="1"> [RestServer](./rest.restserver.md) </td><td markdown="1"> The main REST server instance providing REST API for this application. </td></tr> </tbody></table> ## Methods <table><thead><tr><th> Method </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td markdown="1"> [api(spec)](./rest.restapplication.api.md) </td><td markdown="1"> </td><td markdown="1"> Set the OpenAPI specification that defines the REST API schema for this application. All routes, parameter definitions and return types will be defined in this way. Note that this will override any routes defined via decorators at the controller level (this function takes precedent). </td></tr> <tr><td markdown="1"> [basePath(path)](./rest.restapplication.basepath.md) </td><td markdown="1"> </td><td markdown="1"> Configure the `basePath` for the rest server </td></tr> <tr><td markdown="1"> [bodyParser(bodyParserClass, address)](./rest.restapplication.bodyparser.md) </td><td markdown="1"> </td><td markdown="1"> Bind a body parser to the server context </td></tr> <tr><td markdown="1"> [exportOpenApiSpec(outFile, log)](./rest.restapplication.exportopenapispec.md) </td><td markdown="1"> </td><td markdown="1"> Export the OpenAPI spec to the given json or yaml file </td></tr> <tr><td markdown="1"> [expressMiddleware(key, middleware, options)](./rest.restapplication.expressmiddleware.md) </td><td markdown="1"> </td><td markdown="1"> Bind an Express middleware to this server context </td></tr> <tr><td markdown="1"> [expressMiddleware(middlewareFactory, middlewareConfig, options)](./rest.restapplication.expressmiddleware_1.md) </td><td markdown="1"> </td><td markdown="1"> Bind an Express middleware to this server context </td></tr> <tr><td markdown="1"> [handler(handlerFn)](./rest.restapplication.handler.md) </td><td markdown="1"> </td><td markdown="1"> </td></tr> <tr><td markdown="1"> [middleware(middleware, options)](./rest.restapplication.middleware.md) </td><td markdown="1"> </td><td markdown="1"> Register a middleware function or provider class </td></tr> <tr><td markdown="1"> [mountExpressRouter(basePath, router, spec)](./rest.restapplication.mountexpressrouter.md) </td><td markdown="1"> </td><td markdown="1"> Mount an Express router to expose additional REST endpoints handled via legacy Express-based stack. </td></tr> <tr><td markdown="1"> [redirect(fromPath, toPathOrUrl, statusCode)](./rest.restapplication.redirect.md) </td><td markdown="1"> </td><td markdown="1"> Register a route redirecting callers to a different URL. </td></tr> <tr><td markdown="1"> [route(verb, path, spec, controllerCtor, controllerFactory, methodName)](./rest.restapplication.route.md) </td><td markdown="1"> </td><td markdown="1"> Register a new Controller-based route. </td></tr> <tr><td markdown="1"> [route(verb, path, spec, handler)](./rest.restapplication.route_1.md) </td><td markdown="1"> </td><td markdown="1"> Register a new route invoking a handler function. </td></tr> <tr><td markdown="1"> [route(route)](./rest.restapplication.route_2.md) </td><td markdown="1"> </td><td markdown="1"> Register a new route. </td></tr> <tr><td markdown="1"> [route(verb, path, spec, handler)](./rest.restapplication.route_3.md) </td><td markdown="1"> </td><td markdown="1"> Register a new route. </td></tr> <tr><td markdown="1"> [sequence(sequence)](./rest.restapplication.sequence.md) </td><td markdown="1"> </td><td markdown="1"> </td></tr> <tr><td markdown="1"> [server(server, name)](./rest.restapplication.server.md) </td><td markdown="1"> </td><td markdown="1"> </td></tr> <tr><td markdown="1"> [static(path, rootDir, options)](./rest.restapplication.static.md) </td><td markdown="1"> </td><td markdown="1"> Mount static assets to the REST server. See https://expressjs.com/en/4x/api.html\#express.static </td></tr> </tbody></table>