Page Contents
Home > @loopback/rest > RestApplication
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:
export declare class RestApplication extends Application implements HttpServerLike
Extends: Application
Implements: HttpServerLike
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(parent) | Create a REST application with the given parent context | |
(constructor)(config, parent) | Create a REST application with the given configuration and parent context |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
requestHandler | readonly |
HttpRequestListener | Handle incoming HTTP(S) request by invoking the corresponding Controller method via the configured Sequence. |
restServer | readonly |
RestServer | The main REST server instance providing REST API for this application. |
Methods
Method | Modifiers | Description |
---|---|---|
api(spec) | <p>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.</p><p>Note that this will override any routes defined via decorators at the controller level (this function takes precedent).</p> | |
basePath(path) | Configure the basePath for the rest server |
|
bodyParser(bodyParserClass, address) | Bind a body parser to the server context | |
exportOpenApiSpec(outFile, log) | Export the OpenAPI spec to the given json or yaml file | |
expressMiddleware(key, middleware, options) | Bind an Express middleware to this server context | |
expressMiddleware(middlewareFactory, middlewareConfig, options) | Bind an Express middleware to this server context | |
handler(handlerFn) | ||
middleware(middleware, options) | Register a middleware function or provider class | |
mountExpressRouter(basePath, router, spec) | Mount an Express router to expose additional REST endpoints handled via legacy Express-based stack. | |
redirect(fromPath, toPathOrUrl, statusCode) | Register a route redirecting callers to a different URL. | |
route(verb, path, spec, controllerCtor, controllerFactory, methodName) | Register a new Controller-based route. | |
route(verb, path, spec, handler) | Register a new route invoking a handler function. | |
route(route) | Register a new route. | |
route(verb, path, spec, handler) | Register a new route. | |
sequence(sequence) | ||
server(server, name) | ||
static(path, rootDir, options) | Mount static assets to the REST server. See https://expressjs.com/en/4x/api.html#express.static |