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.


export declare class RestApplication extends Application implements HttpServerLike 

Extends: Application

Implements: HttpServerLike


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


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.


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
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.
server(server, name)    
static(path, rootDir, options)   Mount static assets to the REST server. See