Page Contents

Home > @loopback/rest

rest package

The REST API package for loopback-next.


A REST server for LoopBack 4 application instances, complete with:

  • new custom routing engine (special thanks to @bajtos)! - tools for defining your application routes - OpenAPI 3.0 spec (openapi.json/openapi.yaml) generation using @loopback/openapi-v3 - a default sequence implementation to manage the request and response lifecycle


Class Description
ControllerRoute A route backed by a controller
DefaultSequence The default implementation of SequenceHandler.
InfoSpecEnhancer An OpenAPI spec enhancer to populate info with application metadata (package.json).
MiddlewareSequence A sequence implementation using middleware chains
ParseParamsProvider Provides the function for parsing args in requests at runtime.
RawBodyParser Parsing the request body into Buffer
RegExpRouter Router implementation based on regexp matching
RequestContext A per-request Context combining an IoC container with handler context (request, response, etc.).
RestApplication 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.
RestServer A REST API server for use with Loopback. Add this server to your application by importing the RestComponent.
RoutingTable Routing table
SendProvider Provides the function that populates the response object with the results of the operation.
StreamBodyParser A special body parser to retain request stream as is. It will be used by explicitly setting x-parser to 'stream' in the request body spec.
Trie An implementation of trie for routes. The key hierarchy is built with parts of the route path delimited by /
TrieRouter Router implementation based on trie

Abstract Classes

Abstract Class Description
BaseRoute Base implementation of RouteEntry


Function Description
assignRouterSpec(target, additions)  
compareRoute(route1, route2) Compare two routes by verb/path for sorting
createBodyParserBinding(parserClass, key) Create a binding for the given body parser class
createControllerFactoryForBinding(key) Create a controller factory function for a given binding key
createControllerFactoryForClass(controllerCtor) Create a controller factory function for a given class
createControllerFactoryForInstance(controllerInst) Create a controller factory function for a given instance
createResolvedRoute(route, pathParams)  
createRoutesForController(spec, controllerCtor, controllerFactory) Create routes for a controller with the given spec
getContentType(req) Get the content-type header value from the request
getParserOptions(type, options) Extract parser options based on the parser type
getParserOptions(type, options)  
getParserOptions(type, options)  
getParserOptions(type, options)  
getPathVariables(path) Get all path variables. For example, /root/{foo}/bar => ['foo']
invokeBodyParserMiddleware(handle, request) Parse the request body asynchronously
joinPath(basePath, path)  
normalizeParsingError(err) Normalize parsing errors as 4xx
parseJson(text, reviver, prohibitedKeys) Parse a json string that rejects prohibited keys
parseOperationArgs(request, route, requestBodyParser, options) Parses the request to derive arguments to be passed in for the Application controller method
rebaseOpenApiSpec(spec, basePath)  
sanitizeJsonParse(reviver, prohibitedKeys) Factory to create a reviver function for JSON.parse to sanitize keys
toExpressPath(path) Convert an OpenAPI path to Express (path-to-regexp) style
validateApiPath(path) Validate the path to be compatible with OpenAPI path template. No parameter modifier, custom pattern, or unnamed parameter is allowed.
validateRequestBody(body, requestBodySpec, globalSchemas, options) Check whether the request body is valid according to the provided OpenAPI schema. The JSON schema is generated from the OpenAPI schema which is typically defined by @requestBody(). The validation leverages AJV schema validator.
validateValueAgainstSchema(value, schema, globalSchemas, options) Validate the value against JSON schema.
writeResultToResponse(response, result) Writes the result from Application controller method into the HTTP response


Interface Description
BodyParser Interface to be implemented by body parser extensions
Node A Node in the trie
OpenApiSpecForm The form of OpenAPI specs to be served
OpenApiSpecOptions Options to customize how OpenAPI specs are served
RequestBodyParserOptions <p>Options for request body parsing See</p><p>Built-in parsers retrieve their own options from the request body parser options. The parser specific properties override common ones.</p>
RequestWithSession extending express request type with a session field
ResolvedRoute A route with path parameters resolved
RouteEntry An entry in the routing table
SequenceHandler A sequence handler is a class implementing sequence of actions required to handle an incoming request.
Session interface to set variables in user session
SessionUserProfile user profile to add in session
ValidationOptions Options for request body validation using AJV
ValueValidationOptions Options for any value validation using AJV


Namespace Description
RestBindings RestServer-specific bindings
RestMiddlewareGroups Built-in middleware groups for the REST sequence
RestTags Binding tags for RestServer


Variable Description
REQUEST_BODY_PARSER_TAG Binding tag for request body parser extensions

Type Aliases

Type Alias Description
AjvErrorOptions Options for AJV errors
AjvFactory Factory function for Ajv instances
AjvFormat Ajv format definition with a name
AjvKeyword Ajv keyword definition with a name
BodyParserFunction Plain function for body parsing
BodyParserMiddleware Express body parser function type
ControllerClass Controller class
ControllerFactory A factory function to create controller instances synchronously or asynchronously
FindRoute Find a route matching the incoming request. Throw an error when no route was found.
InvokeMethod Invokes a method defined in the Application Controller
LogError Log information about a failed request.
OperationRetval Return value of a controller method (a function implementing an operation). This is a type alias for “any”, used to distinguish operation results from other “any” typed values.
ParseParams A function to parse OpenAPI operation parameters for a given route
Reject Reject the request with an error.
RequestBody Request body with metadata
RestServerConfig Valid configuration for the RestServer constructor.
RestServerOptions RestServer options
SchemaValidatorCache Cache for AJV schema validators
Send Send the operation response back to the client.
SequenceFunction A sequence function is a function implementing a custom sequence of actions to handle an incoming request.