Page Contents

Home > @loopback/rest

rest package

The REST API package for loopback-next.

Remarks

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

Classes

Class Description
ControllerRoute A route backed by a controller
DefaultSequence The default implementation of SequenceHandler.
FindRouteMiddlewareProvider  
FindRouteProvider  
HttpHandler  
InfoSpecEnhancer An OpenAPI spec enhancer to populate info with application metadata (package.json).
InvokeMethodMiddlewareProvider  
InvokeMethodProvider  
JsonBodyParser  
LogErrorProvider  
MiddlewareSequence A sequence implementation using middleware chains
ParseParamsMiddlewareProvider  
ParseParamsProvider Provides the function for parsing args in requests at runtime.
RawBodyParser Parsing the request body into Buffer
RedirectRoute  
RegExpRouter Router implementation based on regexp matching
RejectProvider  
RequestBodyParser  
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.
RestComponent  
RestServer A REST API server for use with Loopback. Add this server to your application by importing the RestComponent.
Route  
RouteSource  
RoutingTable Routing table
SendProvider Provides the function that populates the response object with the results of the operation.
SendResponseMiddlewareProvider  
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.
TextBodyParser  
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
UrlEncodedBodyParser  

Abstract Classes

Abstract Class Description
BaseRoute Base implementation of RouteEntry

Functions

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

Interfaces

Interface Description
ApiExplorerOptions  
BodyParser Interface to be implemented by body parser extensions
HttpServerLike  
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 https://github.com/expressjs/body-parser/#options</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
ResolvedNode  
ResolvedRoute A route with path parameters resolved
RestRouter  
RestServerResolvedOptions  
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

Namespaces

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

Variables

Variable Description
DEFAULT_LIMIT  
ERR_NO_MULTI_SERVER  
REQUEST_BODY_PARSER_TAG Binding tag for request body parser extensions
SequenceActions  

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
ControllerInstance  
FindRoute Find a route matching the incoming request. Throw an error when no route was found.
HttpRequestListener  
InvokeMethod Invokes a method defined in the Application Controller
LogError Log information about a failed request.
NodeWithValue  
OperationArgs  
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
PathParameterValues  
Reject Reject the request with an error.
RequestBody Request body with metadata
RequestBodyValidationOptions  
RestComponentConfig  
RestRouterOptions  
RestServerConfig Valid configuration for the RestServer constructor.
RestServerOptions RestServer options
RestServerResolvedConfig  
RouterSpec  
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.