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 

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   HttpRequestListener Handle incoming HTTP(S) request by invoking the corresponding Controller method via the configured Sequence.
restServer   RestServer The main REST server instance providing REST API for this application.

Methods

Method Modifiers Description
api(spec)   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).
basePath(path)   Configure the basePath for the rest server
bodyParser(bodyParserClass, address)   Bind a body parser to the server context
handler(handlerFn)    
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