Page Contents
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](/doc/en/lb4/apidocs.rest.controllerroute.html) | A route backed by a controller |
| [DefaultSequence](/doc/en/lb4/apidocs.rest.defaultsequence.html) | The default implementation of SequenceHandler. |
| [FindRouteMiddlewareProvider](/doc/en/lb4/apidocs.rest.findroutemiddlewareprovider.html) | |
| [FindRouteProvider](/doc/en/lb4/apidocs.rest.findrouteprovider.html) | |
| [HttpHandler](/doc/en/lb4/apidocs.rest.httphandler.html) | |
| [InfoSpecEnhancer](/doc/en/lb4/apidocs.rest.infospecenhancer.html) | An OpenAPI spec enhancer to populate `info` with application metadata (package.json). |
| [InvokeMethodMiddlewareProvider](/doc/en/lb4/apidocs.rest.invokemethodmiddlewareprovider.html) | |
| [InvokeMethodProvider](/doc/en/lb4/apidocs.rest.invokemethodprovider.html) | |
| [JsonBodyParser](/doc/en/lb4/apidocs.rest.jsonbodyparser.html) | |
| [LogErrorProvider](/doc/en/lb4/apidocs.rest.logerrorprovider.html) | |
| [MiddlewareSequence](/doc/en/lb4/apidocs.rest.middlewaresequence.html) | A sequence implementation using middleware chains |
| [ParseParamsMiddlewareProvider](/doc/en/lb4/apidocs.rest.parseparamsmiddlewareprovider.html) | |
| [ParseParamsProvider](/doc/en/lb4/apidocs.rest.parseparamsprovider.html) | Provides the function for parsing args in requests at runtime. |
| [RawBodyParser](/doc/en/lb4/apidocs.rest.rawbodyparser.html) | Parsing the request body into Buffer |
| [RedirectRoute](/doc/en/lb4/apidocs.rest.redirectroute.html) | |
| [RegExpRouter](/doc/en/lb4/apidocs.rest.regexprouter.html) | Router implementation based on regexp matching |
| [RejectProvider](/doc/en/lb4/apidocs.rest.rejectprovider.html) | |
| [RequestBodyParser](/doc/en/lb4/apidocs.rest.requestbodyparser.html) | |
| [RequestContext](/doc/en/lb4/apidocs.rest.requestcontext.html) | A per-request Context combining an IoC container with handler context (request, response, etc.). |
| [RestApplication](/doc/en/lb4/apidocs.rest.restapplication.html) | 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](/doc/en/lb4/apidocs.rest.restcomponent.html) | |
| [RestServer](/doc/en/lb4/apidocs.rest.restserver.html) | A REST API server for use with Loopback. Add this server to your application by importing the RestComponent. |
| [Route](/doc/en/lb4/apidocs.rest.route.html) | |
| [RouteSource](/doc/en/lb4/apidocs.rest.routesource.html) | |
| [RoutingTable](/doc/en/lb4/apidocs.rest.routingtable.html) | Routing table |
| [SendProvider](/doc/en/lb4/apidocs.rest.sendprovider.html) | Provides the function that populates the response object with the results of the operation. |
| [SendResponseMiddlewareProvider](/doc/en/lb4/apidocs.rest.sendresponsemiddlewareprovider.html) | |
| [StreamBodyParser](/doc/en/lb4/apidocs.rest.streambodyparser.html) | 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](/doc/en/lb4/apidocs.rest.textbodyparser.html) | |
| [Trie](/doc/en/lb4/apidocs.rest.trie.html) | An implementation of trie for routes. The key hierarchy is built with parts of the route path delimited by `/` |
| [TrieRouter](/doc/en/lb4/apidocs.rest.trierouter.html) | Router implementation based on trie |
| [UrlEncodedBodyParser](/doc/en/lb4/apidocs.rest.urlencodedbodyparser.html) |
Abstract Classes
| Abstract Class | Description |
|---|---|
| [BaseRoute](/doc/en/lb4/apidocs.rest.baseroute.html) | Base implementation of RouteEntry |
Functions
| Function | Description |
|---|---|
| [assignRouterSpec(target, additions)](/doc/en/lb4/apidocs.rest.assignrouterspec.html) | |
| [compareRoute(route1, route2)](/doc/en/lb4/apidocs.rest.compareroute.html) | Compare two routes by verb/path for sorting |
| [createBodyParserBinding(parserClass, key)](/doc/en/lb4/apidocs.rest.createbodyparserbinding.html) | Create a binding for the given body parser class |
| [createControllerFactoryForBinding(key)](/doc/en/lb4/apidocs.rest.createcontrollerfactoryforbinding.html) | Create a controller factory function for a given binding key |
| [createControllerFactoryForClass(controllerCtor)](/doc/en/lb4/apidocs.rest.createcontrollerfactoryforclass.html) | Create a controller factory function for a given class |
| [createControllerFactoryForInstance(controllerInst)](/doc/en/lb4/apidocs.rest.createcontrollerfactoryforinstance.html) | Create a controller factory function for a given instance |
| [createResolvedRoute(route, pathParams)](/doc/en/lb4/apidocs.rest.createresolvedroute.html) | |
| [createRoutesForController(spec, controllerCtor, controllerFactory)](/doc/en/lb4/apidocs.rest.createroutesforcontroller.html) | Create routes for a controller with the given spec |
| [getContentType(req)](/doc/en/lb4/apidocs.rest.getcontenttype.html) | Get the content-type header value from the request |
| [getParserOptions(type, options)](/doc/en/lb4/apidocs.rest.getparseroptions.html) | Extract parser options based on the parser type |
| [getParserOptions(type, options)](/doc/en/lb4/apidocs.rest.getparseroptions_1.html) | |
| [getParserOptions(type, options)](/doc/en/lb4/apidocs.rest.getparseroptions_2.html) | |
| [getParserOptions(type, options)](/doc/en/lb4/apidocs.rest.getparseroptions_3.html) | |
| [getPathVariables(path)](/doc/en/lb4/apidocs.rest.getpathvariables.html) | Get all path variables. For example, `/root/{foo}/bar` => `['foo']` |
| [invokeBodyParserMiddleware(handle, request)](/doc/en/lb4/apidocs.rest.invokebodyparsermiddleware.html) | Parse the request body asynchronously |
| [joinPath(basePath, path)](/doc/en/lb4/apidocs.rest.joinpath.html) | |
| [normalizeParsingError(err)](/doc/en/lb4/apidocs.rest.normalizeparsingerror.html) | Normalize parsing errors as `4xx` |
| [parseJson(text, reviver, prohibitedKeys)](/doc/en/lb4/apidocs.rest.parsejson.html) | Parse a json string that rejects prohibited keys |
| [parseOperationArgs(request, route, requestBodyParser, options)](/doc/en/lb4/apidocs.rest.parseoperationargs.html) | Parses the request to derive arguments to be passed in for the Application controller method |
| [rebaseOpenApiSpec(spec, basePath)](/doc/en/lb4/apidocs.rest.rebaseopenapispec.html) | |
| [sanitizeJsonParse(reviver, prohibitedKeys)](/doc/en/lb4/apidocs.rest.sanitizejsonparse.html) | Factory to create a reviver function for `JSON.parse` to sanitize keys |
| [toExpressPath(path)](/doc/en/lb4/apidocs.rest.toexpresspath.html) | Convert an OpenAPI path to Express (path-to-regexp) style |
| [validateApiPath(path)](/doc/en/lb4/apidocs.rest.validateapipath.html) | 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)](/doc/en/lb4/apidocs.rest.validaterequestbody.html) | 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)](/doc/en/lb4/apidocs.rest.validatevalueagainstschema.html) | Validate the value against JSON schema. |
| [writeResultToResponse(response, result)](/doc/en/lb4/apidocs.rest.writeresulttoresponse.html) | Writes the result from Application controller method into the HTTP response |
Interfaces
| Interface | Description |
|---|---|
| [ApiExplorerOptions](/doc/en/lb4/apidocs.rest.apiexploreroptions.html) | |
| [BodyParser](/doc/en/lb4/apidocs.rest.bodyparser.html) | Interface to be implemented by body parser extensions |
| [HttpServerLike](/doc/en/lb4/apidocs.rest.httpserverlike.html) | |
| [Node](/doc/en/lb4/apidocs.rest.node.html) | A Node in the trie |
| [OpenApiSpecForm](/doc/en/lb4/apidocs.rest.openapispecform.html) | The form of OpenAPI specs to be served |
| [OpenApiSpecOptions](/doc/en/lb4/apidocs.rest.openapispecoptions.html) | Options to customize how OpenAPI specs are served |
| [RequestBodyParserOptions](/doc/en/lb4/apidocs.rest.requestbodyparseroptions.html) | Options for request body parsing See https://github.com/expressjs/body-parser/\#options Built-in parsers retrieve their own options from the request body parser options. The parser specific properties override common ones. |
| [RequestWithSession](/doc/en/lb4/apidocs.rest.requestwithsession.html) | extending express request type with a session field |
| [ResolvedNode](/doc/en/lb4/apidocs.rest.resolvednode.html) | |
| [ResolvedRoute](/doc/en/lb4/apidocs.rest.resolvedroute.html) | A route with path parameters resolved |
| [RestRouter](/doc/en/lb4/apidocs.rest.restrouter.html) | |
| [RestServerResolvedOptions](/doc/en/lb4/apidocs.rest.restserverresolvedoptions.html) | |
| [RouteEntry](/doc/en/lb4/apidocs.rest.routeentry.html) | An entry in the routing table |
| [SequenceHandler](/doc/en/lb4/apidocs.rest.sequencehandler.html) | A sequence handler is a class implementing sequence of actions required to handle an incoming request. |
| [Session](/doc/en/lb4/apidocs.rest.session.html) | interface to set variables in user session |
| [SessionUserProfile](/doc/en/lb4/apidocs.rest.sessionuserprofile.html) | user profile to add in session |
| [ValidationOptions](/doc/en/lb4/apidocs.rest.validationoptions.html) | Options for request body validation using AJV |
| [ValueValidationOptions](/doc/en/lb4/apidocs.rest.valuevalidationoptions.html) | Options for any value validation using AJV |
Namespaces
| Namespace | Description |
|---|---|
| [builtinParsers](/doc/en/lb4/apidocs.rest.builtinparsers.html) | |
| [RestBindings](/doc/en/lb4/apidocs.rest.restbindings.html) | RestServer-specific bindings |
| [RestHttpErrors](/doc/en/lb4/apidocs.rest.resthttperrors.html) | |
| [RestMiddlewareGroups](/doc/en/lb4/apidocs.rest.restmiddlewaregroups.html) | Built-in middleware groups for the REST sequence |
| [RestTags](/doc/en/lb4/apidocs.rest.resttags.html) | Binding tags for RestServer |
Variables
| Variable | Description |
|---|---|
| [DEFAULT\_LIMIT](/doc/en/lb4/apidocs.rest.default_limit.html) | |
| [ERR\_NO\_MULTI\_SERVER](/doc/en/lb4/apidocs.rest.err_no_multi_server.html) | |
| [REQUEST\_BODY\_PARSER\_TAG](/doc/en/lb4/apidocs.rest.request_body_parser_tag.html) | Binding tag for request body parser extensions |
| [SequenceActions](/doc/en/lb4/apidocs.rest.sequenceactions.html) |
Type Aliases
| Type Alias | Description |
|---|---|
| [AjvErrorOptions](/doc/en/lb4/apidocs.rest.ajverroroptions.html) | Options for AJV errors |
| [AjvFactory](/doc/en/lb4/apidocs.rest.ajvfactory.html) | Factory function for Ajv instances |
| [AjvFormat](/doc/en/lb4/apidocs.rest.ajvformat.html) | Ajv format definition with a name |
| [AjvKeyword](/doc/en/lb4/apidocs.rest.ajvkeyword.html) | Ajv keyword definition with a name |
| [BodyParserFunction](/doc/en/lb4/apidocs.rest.bodyparserfunction.html) | Plain function for body parsing |
| [BodyParserMiddleware](/doc/en/lb4/apidocs.rest.bodyparsermiddleware.html) | Express body parser function type |
| [ControllerClass](/doc/en/lb4/apidocs.rest.controllerclass.html) | Controller class |
| [ControllerFactory](/doc/en/lb4/apidocs.rest.controllerfactory.html) | A factory function to create controller instances synchronously or asynchronously |
| [ControllerInstance](/doc/en/lb4/apidocs.rest.controllerinstance.html) | |
| [FindRoute](/doc/en/lb4/apidocs.rest.findroute.html) | Find a route matching the incoming request. Throw an error when no route was found. |
| [HttpRequestListener](/doc/en/lb4/apidocs.rest.httprequestlistener.html) | |
| [InvokeMethod](/doc/en/lb4/apidocs.rest.invokemethod.html) | Invokes a method defined in the Application Controller |
| [LogError](/doc/en/lb4/apidocs.rest.logerror.html) | Log information about a failed request. |
| [NodeWithValue](/doc/en/lb4/apidocs.rest.nodewithvalue.html) | |
| [OperationArgs](/doc/en/lb4/apidocs.rest.operationargs.html) | |
| [OperationRetval](/doc/en/lb4/apidocs.rest.operationretval.html) | 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](/doc/en/lb4/apidocs.rest.parseparams.html) | A function to parse OpenAPI operation parameters for a given route |
| [PathParameterValues](/doc/en/lb4/apidocs.rest.pathparametervalues.html) | |
| [Reject](/doc/en/lb4/apidocs.rest.reject.html) | Reject the request with an error. |
| [RequestBody](/doc/en/lb4/apidocs.rest.requestbody.html) | Request body with metadata |
| [RequestBodyValidationOptions](/doc/en/lb4/apidocs.rest.requestbodyvalidationoptions.html) | |
| [RestComponentConfig](/doc/en/lb4/apidocs.rest.restcomponentconfig.html) | |
| [RestRouterOptions](/doc/en/lb4/apidocs.rest.restrouteroptions.html) | |
| [RestServerConfig](/doc/en/lb4/apidocs.rest.restserverconfig.html) | Valid configuration for the RestServer constructor. |
| [RestServerOptions](/doc/en/lb4/apidocs.rest.restserveroptions.html) | RestServer options |
| [RestServerResolvedConfig](/doc/en/lb4/apidocs.rest.restserverresolvedconfig.html) | |
| [RouterSpec](/doc/en/lb4/apidocs.rest.routerspec.html) | |
| [SchemaValidatorCache](/doc/en/lb4/apidocs.rest.schemavalidatorcache.html) | Cache for AJV schema validators |
| [Send](/doc/en/lb4/apidocs.rest.send.html) | Send the operation response back to the client. |
| [SequenceFunction](/doc/en/lb4/apidocs.rest.sequencefunction.html) | A sequence function is a function implementing a custom sequence of actions to handle an incoming request. |