@loopback/rest

  • Version 14.0.0
  • Published
  • 617 kB
  • 31 dependencies
  • MIT license

Install

npm i @loopback/rest
yarn add @loopback/rest
pnpm add @loopback/rest

Overview

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

Index

Variables

Functions

Classes

Interfaces

Type Aliases

Namespaces

Variables

variable DEFAULT_LIMIT

const DEFAULT_LIMIT: string;

    variable ERR_NO_MULTI_SERVER

    const ERR_NO_MULTI_SERVER: string;

      variable REQUEST_BODY_PARSER_TAG

      const REQUEST_BODY_PARSER_TAG: string;
      • Binding tag for request body parser extensions

      variable SequenceActions

      const SequenceActions: typeof RestBindings.SequenceActions;

        Functions

        function assignRouterSpec

        assignRouterSpec: (target: RouterSpec, additions: RouterSpec) => void;

          function compareRoute

          compareRoute: (
          route1: Pick<RouteEntry, 'verb' | 'path'>,
          route2: Pick<RouteEntry, 'verb' | 'path'>
          ) => number;
          • Compare two routes by verb/path for sorting

            Parameter route1

            First route entry

            Parameter route2

            Second route entry

          function createBodyParserBinding

          createBodyParserBinding: (
          parserClass: Constructor<BodyParser>,
          key?: BindingAddress<BodyParser>
          ) => Binding<BodyParser>;
          • Create a binding for the given body parser class

            Parameter parserClass

            Body parser class

            Parameter key

            Optional binding address

          function createControllerFactoryForBinding

          createControllerFactoryForBinding: <T extends object>(
          key: string
          ) => ControllerFactory<T>;
          • Create a controller factory function for a given binding key

            Parameter key

            Binding key

          function createControllerFactoryForClass

          createControllerFactoryForClass: <T extends object>(
          controllerCtor: Constructor<T>
          ) => ControllerFactory<T>;
          • Create a controller factory function for a given class

            Parameter controllerCtor

            Controller class

          function createControllerFactoryForInstance

          createControllerFactoryForInstance: <T extends object>(
          controllerInst: T
          ) => ControllerFactory<T>;
          • Create a controller factory function for a given instance

            Parameter controllerCtor

            Controller instance

          function createResolvedRoute

          createResolvedRoute: (
          route: RouteEntry,
          pathParams: PathParameterValues
          ) => ResolvedRoute;

            function createRoutesForController

            createRoutesForController: <T extends object>(
            spec: ControllerSpec,
            controllerCtor: Constructor<T>,
            controllerFactory?: ControllerFactory<T>
            ) => ControllerRoute<T>[];
            • Create routes for a controller with the given spec

              Parameter spec

              Controller spec

              Parameter controllerCtor

              Controller class

              Parameter controllerFactory

              Controller factory

            function getContentType

            getContentType: (req: Request) => string | undefined;
            • Get the content-type header value from the request

              Parameter req

              Http request

            function getParserOptions

            getParserOptions: {
            (type: 'json', options: RequestBodyParserOptions): OptionsJson;
            (type: 'urlencoded', options: RequestBodyParserOptions): OptionsUrlencoded;
            (type: 'text', options: RequestBodyParserOptions): OptionsText;
            (type: 'raw', options: RequestBodyParserOptions): Options;
            };
            • Extract parser options based on the parser type

              Parameter type

              json|urlencoded|text

              Parameter options

            function getPathVariables

            getPathVariables: (path: string) => RegExpMatchArray | null;
            • Get all path variables. For example, /root/{foo}/bar => ['foo']

            function invokeBodyParserMiddleware

            invokeBodyParserMiddleware: (
            handle: BodyParserMiddleware,
            request: Request
            ) => Promise<any>;
            • Parse the request body asynchronously

              Parameter handle

              The express middleware handler

              Parameter request

              Http request

            function joinPath

            joinPath: (basePath: string, path: string) => string;

              function normalizeParsingError

              normalizeParsingError: (err: HttpError) => HttpError<number>;
              • Normalize parsing errors as 4xx

                Parameter err

              function parseJson

              parseJson: (
              text: string,
              reviver?: (key: any, value: any) => any,
              prohibitedKeys?: string[]
              ) => any;
              • Parse a json string that rejects prohibited keys

                Parameter text

                JSON string

                Parameter reviver

                Optional reviver function for JSON.parse

                Parameter prohibitedKeys

                An array of keys to be rejected

              function parseOperationArgs

              parseOperationArgs: (
              request: Request,
              route: ResolvedRoute,
              requestBodyParser?: RequestBodyParser,
              options?: ValidationOptions
              ) => Promise<OperationArgs>;
              • Parses the request to derive arguments to be passed in for the Application controller method

                Parameter request

                Incoming HTTP request

                Parameter route

                Resolved Route

              function rebaseOpenApiSpec

              rebaseOpenApiSpec: <T extends OpenApiSpec>(spec: T, basePath: string) => T;

                function sanitizeJsonParse

                sanitizeJsonParse: (
                reviver?: (key: any, value: any) => any,
                prohibitedKeys?: string[]
                ) => (key: string, value: any) => any;
                • Factory to create a reviver function for JSON.parse to sanitize keys

                  Parameter reviver

                  Reviver function

                  Parameter prohibitedKeys

                  An array of keys to be rejected

                function toExpressPath

                toExpressPath: (path: string) => string;
                • Convert an OpenAPI path to Express (path-to-regexp) style

                  Parameter path

                  OpenAPI path with optional variables as {var}

                function validateApiPath

                validateApiPath: (path?: string) => string;
                • Validate the path to be compatible with OpenAPI path template. No parameter modifier, custom pattern, or unnamed parameter is allowed.

                function validateRequestBody

                validateRequestBody: (
                body: RequestBody,
                requestBodySpec?: RequestBodyObject,
                globalSchemas?: SchemasObject,
                options?: ValidationOptions
                ) => Promise<void>;
                • 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.

                  Parameter body

                  The request body parsed from an HTTP request.

                  Parameter requestBodySpec

                  The OpenAPI requestBody specification defined in @requestBody().

                  Parameter globalSchemas

                  The referenced schemas generated from OpenAPISpec.components.schemas.

                  Parameter options

                  Request body validation options for AJV

                function validateValueAgainstSchema

                validateValueAgainstSchema: (
                value: any,
                schema: SchemaObject | ReferenceObject,
                globalSchemas?: SchemasObject,
                options?: ValueValidationOptions
                ) => Promise<any>;
                • Validate the value against JSON schema.

                  Parameter value

                  The data value.

                  Parameter schema

                  The JSON schema used to perform the validation.

                  Parameter globalSchemas

                  Schema references.

                  Parameter options

                  Value validation options.

                function writeResultToResponse

                writeResultToResponse: (response: Response, result: OperationRetval) => void;
                • Writes the result from Application controller method into the HTTP response

                  Parameter response

                  HTTP Response

                  Parameter result

                  Result from the API to write into HTTP Response

                Classes

                class BaseRoute

                abstract class BaseRoute implements RouteEntry {}
                • Base implementation of RouteEntry

                constructor

                constructor(verb: string, path: string, spec: OperationObject);
                • Construct a new route

                  Parameter verb

                  http verb

                  Parameter path

                  http request path pattern

                  Parameter spec

                  OpenAPI operation spec

                property path

                readonly path: string;

                  property spec

                  readonly spec: OperationObject;

                    property verb

                    readonly verb: string;

                      method describe

                      describe: () => string;

                        method invokeHandler

                        abstract invokeHandler: (
                        requestContext: Context,
                        args: OperationArgs
                        ) => Promise<OperationRetval>;

                          method toString

                          toString: () => string;

                            method updateBindings

                            abstract updateBindings: (requestContext: Context) => void;

                              class ControllerRoute

                              class ControllerRoute<T extends object> extends BaseRoute {}
                              • A route backed by a controller

                              constructor

                              constructor(
                              verb: string,
                              path: string,
                              spec: OperationObject,
                              controllerCtor: Constructor<T>,
                              controllerFactory?: ControllerFactory<T>,
                              methodName?: string
                              );
                              • Construct a controller based route

                                Parameter verb

                                http verb

                                Parameter path

                                http request path

                                Parameter spec

                                OpenAPI operation spec

                                Parameter controllerCtor

                                Controller class

                                Parameter controllerFactory

                                A factory function to create a controller instance

                                Parameter methodName

                                Controller method name, default to x-operation-name

                              method describe

                              describe: () => string;

                                method invokeHandler

                                invokeHandler: (
                                requestContext: Context,
                                args: OperationArgs
                                ) => Promise<OperationRetval>;

                                  method updateBindings

                                  updateBindings: (requestContext: Context) => void;

                                    class DefaultSequence

                                    class DefaultSequence implements SequenceHandler {}
                                    • The default implementation of SequenceHandler.

                                      Remarks

                                      This class implements default Sequence for the LoopBack framework. Default sequence is used if user hasn't defined their own Sequence for their application.

                                      Sequence constructor() and run() methods are invoked from [[http-handler]] when the API request comes in. User defines APIs in their Application Controller class.

                                      Example 1

                                      User can bind their own Sequence to app as shown below

                                      app.bind(CoreBindings.SEQUENCE).toClass(MySequence);

                                    constructor

                                    constructor(
                                    findRoute: FindRoute,
                                    parseParams: ParseParams,
                                    invoke: InvokeMethod,
                                    send: Send,
                                    reject: Reject
                                    );
                                    • Constructor: Injects findRoute, invokeMethod & logError methods as promises.

                                      Parameter findRoute

                                      Finds the appropriate controller method, spec and args for invocation (injected via SequenceActions.FIND_ROUTE).

                                      Parameter parseParams

                                      The parameter parsing function (injected via SequenceActions.PARSE_PARAMS).

                                      Parameter invoke

                                      Invokes the method specified by the route (injected via SequenceActions.INVOKE_METHOD).

                                      Parameter send

                                      The action to merge the invoke result with the response (injected via SequenceActions.SEND)

                                      Parameter reject

                                      The action to take if the invoke returns a rejected promise result (injected via SequenceActions.REJECT).

                                    property findRoute

                                    protected findRoute: FindRoute;

                                      property invoke

                                      protected invoke: InvokeMethod;

                                        property invokeMiddleware

                                        protected invokeMiddleware: InvokeMiddleware;
                                        • Optional invoker for registered middleware in a chain. To be injected via SequenceActions.INVOKE_MIDDLEWARE.

                                        property parseParams

                                        protected parseParams: ParseParams;

                                          property reject

                                          reject: Reject;

                                            property send

                                            send: Send;

                                              method handle

                                              handle: (context: RequestContext) => Promise<void>;
                                              • Runs the default sequence. Given a handler context (request and response), running the sequence will produce a response or an error.

                                                Default sequence executes these steps - Executes middleware for CORS, OpenAPI spec endpoints - Finds the appropriate controller method, swagger spec and args for invocation - Parses HTTP request to get API argument list - Invokes the API which is defined in the Application Controller - Writes the result from API into the HTTP response - Error is caught and logged using 'logError' if any of the above steps in the sequence fails with an error.

                                                Parameter context

                                                The request context: HTTP request and response objects, per-request IoC container and more.

                                              class FindRouteMiddlewareProvider

                                              class FindRouteMiddlewareProvider implements Provider<Middleware> {}

                                                method value

                                                value: () => Middleware;

                                                  class FindRouteProvider

                                                  class FindRouteProvider {}

                                                    method value

                                                    static value: (context: Context, handler: HttpHandler) => FindRoute;

                                                      class HttpHandler

                                                      class HttpHandler {}

                                                        constructor

                                                        constructor(_rootContext: Context, _serverConfig: any, _routes?: RoutingTable);

                                                          property handleRequest

                                                          handleRequest: (request: Request, response: Response) => Promise<void>;

                                                            method describeApiPaths

                                                            describeApiPaths: () => PathObject;

                                                              method findRoute

                                                              findRoute: (request: Request) => ResolvedRoute;

                                                                method getApiComponents

                                                                getApiComponents: () => ComponentsObject;

                                                                  method getApiDefinitions

                                                                  getApiDefinitions: () => { [schema: string]: any };
                                                                  • Deprecated

                                                                    Use getApiComponents

                                                                  method registerApiComponents

                                                                  registerApiComponents: (defs: ComponentsObject) => void;
                                                                  • Merge components into the OpenApi spec

                                                                    Parameter defs

                                                                    Components

                                                                  method registerApiDefinitions

                                                                  registerApiDefinitions: (defs: SchemasObject) => void;
                                                                  • Parameter defs

                                                                    Schemas

                                                                    Deprecated

                                                                    Use registerApiComponents

                                                                  method registerController

                                                                  registerController: <T extends object>(
                                                                  spec: ControllerSpec,
                                                                  controllerCtor: Constructor<T>,
                                                                  controllerFactory?: ControllerFactory<T>
                                                                  ) => void;

                                                                    method registerRoute

                                                                    registerRoute: (route: RouteEntry) => void;

                                                                      class InfoSpecEnhancer

                                                                      class InfoSpecEnhancer implements OASEnhancer {}
                                                                      • An OpenAPI spec enhancer to populate info with application metadata (package.json).

                                                                      constructor

                                                                      constructor(pkg?: any);

                                                                        property name

                                                                        name: string;

                                                                          property pkg

                                                                          readonly pkg?: any;

                                                                            method modifySpec

                                                                            modifySpec: (spec: OpenApiSpec) => OpenApiSpec;

                                                                              class InvokeMethodMiddlewareProvider

                                                                              class InvokeMethodMiddlewareProvider implements Provider<Middleware> {}

                                                                                method value

                                                                                value: () => Middleware;

                                                                                  class InvokeMethodProvider

                                                                                  class InvokeMethodProvider {}

                                                                                    method value

                                                                                    static value: (context: Context) => InvokeMethod;

                                                                                      class JsonBodyParser

                                                                                      class JsonBodyParser implements BodyParser {}

                                                                                        constructor

                                                                                        constructor(options?: RequestBodyParserOptions);

                                                                                          property name

                                                                                          name: Symbol;

                                                                                            method parse

                                                                                            parse: (request: Request) => Promise<RequestBody>;

                                                                                              method supports

                                                                                              supports: (mediaType: string) => boolean;

                                                                                                class LogErrorProvider

                                                                                                class LogErrorProvider {}

                                                                                                  method value

                                                                                                  static value: () => LogError;

                                                                                                    class MiddlewareSequence

                                                                                                    class MiddlewareSequence implements SequenceHandler {}
                                                                                                    • A sequence implementation using middleware chains

                                                                                                    constructor

                                                                                                    constructor(
                                                                                                    context: Context,
                                                                                                    invokeMiddleware: InvokeMiddleware,
                                                                                                    options?: InvokeMiddlewareOptions
                                                                                                    );
                                                                                                    • Constructor: Injects InvokeMiddleware and InvokeMiddlewareOptions

                                                                                                      Parameter invokeMiddleware

                                                                                                      invoker for registered middleware in a chain. To be injected via RestBindings.INVOKE_MIDDLEWARE_SERVICE.

                                                                                                    property defaultOptions

                                                                                                    static defaultOptions: InvokeMiddlewareOptions;

                                                                                                      property invokeMiddleware

                                                                                                      readonly invokeMiddleware: InvokeMiddleware;

                                                                                                        property options

                                                                                                        readonly options: InvokeMiddlewareOptions;

                                                                                                          method handle

                                                                                                          handle: (context: RequestContext) => Promise<void>;
                                                                                                          • Runs the default sequence. Given a handler context (request and response), running the sequence will produce a response or an error.

                                                                                                            Default sequence executes these groups of middleware:

                                                                                                            - cors: Enforces CORS - openApiSpec: Serves OpenAPI specs - findRoute: Finds the appropriate controller method, swagger spec and args for invocation - parseParams: Parses HTTP request to get API argument list - invokeMethod: Invokes the API which is defined in the Application controller method

                                                                                                            In front of the groups above, we have a special middleware called sendResponse, which first invokes downstream middleware to get a result and handles the result or error respectively.

                                                                                                            - Writes the result from API into the HTTP response (if the HTTP response has not been produced yet by the middleware chain. - Catches error logs it using 'logError' if any of the above steps in the sequence fails with an error.

                                                                                                            Parameter context

                                                                                                            The request context: HTTP request and response objects, per-request IoC container and more.

                                                                                                          class ParseParamsMiddlewareProvider

                                                                                                          class ParseParamsMiddlewareProvider implements Provider<Middleware> {}

                                                                                                            method value

                                                                                                            value: () => Middleware;

                                                                                                              class ParseParamsProvider

                                                                                                              class ParseParamsProvider {}
                                                                                                              • Provides the function for parsing args in requests at runtime.

                                                                                                                Returns

                                                                                                                The handler function that will parse request args.

                                                                                                              method value

                                                                                                              static value: (
                                                                                                              requestBodyParser: RequestBodyParser,
                                                                                                              validationOptions: ValidationOptions | undefined,
                                                                                                              ajvFactory: AjvFactory
                                                                                                              ) => ParseParams;

                                                                                                                class RawBodyParser

                                                                                                                class RawBodyParser implements BodyParser {}
                                                                                                                • Parsing the request body into Buffer

                                                                                                                constructor

                                                                                                                constructor(options?: RequestBodyParserOptions);

                                                                                                                  property name

                                                                                                                  name: Symbol;

                                                                                                                    method parse

                                                                                                                    parse: (request: Request) => Promise<RequestBody>;

                                                                                                                      method supports

                                                                                                                      supports: (mediaType: string) => boolean;

                                                                                                                        class RedirectRoute

                                                                                                                        class RedirectRoute implements RouteEntry, ResolvedRoute {}

                                                                                                                          constructor

                                                                                                                          constructor(sourcePath: string, targetLocation: string, statusCode?: number);

                                                                                                                            property path

                                                                                                                            readonly path: string;

                                                                                                                              property pathParams

                                                                                                                              readonly pathParams: PathParameterValues;

                                                                                                                                property schemas

                                                                                                                                readonly schemas: SchemasObject;

                                                                                                                                  property sourcePath

                                                                                                                                  readonly sourcePath: string;

                                                                                                                                    property spec

                                                                                                                                    readonly spec: OperationObject;

                                                                                                                                      property statusCode

                                                                                                                                      readonly statusCode: number;

                                                                                                                                        property targetLocation

                                                                                                                                        readonly targetLocation: string;

                                                                                                                                          property verb

                                                                                                                                          readonly verb: string;

                                                                                                                                            method describe

                                                                                                                                            describe: () => string;

                                                                                                                                              method invokeHandler

                                                                                                                                              invokeHandler: (
                                                                                                                                              { response }: RequestContext,
                                                                                                                                              args: OperationArgs
                                                                                                                                              ) => Promise<OperationRetval>;

                                                                                                                                                method isRedirectRoute

                                                                                                                                                static isRedirectRoute: (obj: any) => obj is RedirectRoute;
                                                                                                                                                • type guard type checker for this class

                                                                                                                                                  Parameter obj

                                                                                                                                                method updateBindings

                                                                                                                                                updateBindings: (requestContext: RequestContext) => void;

                                                                                                                                                  class RegExpRouter

                                                                                                                                                  class RegExpRouter extends BaseRouter {}
                                                                                                                                                  • Router implementation based on regexp matching

                                                                                                                                                  constructor

                                                                                                                                                  constructor(options?: RestRouterOptions);

                                                                                                                                                    method addRouteWithPathVars

                                                                                                                                                    protected addRouteWithPathVars: (route: RouteEntry) => void;

                                                                                                                                                      method findRouteWithPathVars

                                                                                                                                                      protected findRouteWithPathVars: (
                                                                                                                                                      verb: string,
                                                                                                                                                      path: string
                                                                                                                                                      ) => ResolvedRoute | undefined;

                                                                                                                                                        method listRoutesWithPathVars

                                                                                                                                                        protected listRoutesWithPathVars: () => RegExpRouteEntry[];

                                                                                                                                                          class RejectProvider

                                                                                                                                                          class RejectProvider {}

                                                                                                                                                            method value

                                                                                                                                                            static value: (
                                                                                                                                                            logError: LogError,
                                                                                                                                                            errorWriterOptions?: ErrorWriterOptions
                                                                                                                                                            ) => Reject;

                                                                                                                                                              class RequestBodyParser

                                                                                                                                                              class RequestBodyParser {}

                                                                                                                                                                constructor

                                                                                                                                                                constructor(parsers?: BodyParser[], ctx?: any);

                                                                                                                                                                  property parsers

                                                                                                                                                                  readonly parsers: BodyParser[];

                                                                                                                                                                    method loadRequestBodyIfNeeded

                                                                                                                                                                    loadRequestBodyIfNeeded: (
                                                                                                                                                                    operationSpec: OperationObject,
                                                                                                                                                                    request: Request
                                                                                                                                                                    ) => Promise<RequestBody>;

                                                                                                                                                                      class RequestContext

                                                                                                                                                                      class RequestContext extends MiddlewareContext implements HandlerContext {}
                                                                                                                                                                      • A per-request Context combining an IoC container with handler context (request, response, etc.).

                                                                                                                                                                      constructor

                                                                                                                                                                      constructor(
                                                                                                                                                                      request: Request,
                                                                                                                                                                      response: Response,
                                                                                                                                                                      parent: Context,
                                                                                                                                                                      serverConfig: any,
                                                                                                                                                                      name?: string
                                                                                                                                                                      );

                                                                                                                                                                        property basePath

                                                                                                                                                                        readonly basePath: string;
                                                                                                                                                                        • Get the effective base path of the incoming request. This base path combines baseUrl provided by Express when LB4 handler is mounted on a non-root path, with the basePath value configured at LB4 side.

                                                                                                                                                                        property request

                                                                                                                                                                        readonly request: Request;

                                                                                                                                                                          property requestedBaseUrl

                                                                                                                                                                          readonly requestedBaseUrl: string;
                                                                                                                                                                          • Get the base URL used by the client to make the request. This URL contains the protocol, hostname, port and base path. The path of the invoked route and query string is not included.

                                                                                                                                                                            Please note these values may be different from what we are observing at HTTP/TCP level, because reverse proxies like nginx are rewriting them.

                                                                                                                                                                          property requestedProtocol

                                                                                                                                                                          readonly requestedProtocol: string;
                                                                                                                                                                          • Get the protocol used by the client to make the request. Please note this protocol may be different from what we are observing at HTTP/TCP level, because reverse proxies like nginx or sidecars like Envoy are switching between protocols.

                                                                                                                                                                          property response

                                                                                                                                                                          readonly response: Response;

                                                                                                                                                                            property serverConfig

                                                                                                                                                                            readonly serverConfig: any;

                                                                                                                                                                              method setupBindings

                                                                                                                                                                              protected setupBindings: () => void;

                                                                                                                                                                                class RestApplication

                                                                                                                                                                                class RestApplication extends Application implements HttpServerLike {}
                                                                                                                                                                                • 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.

                                                                                                                                                                                constructor

                                                                                                                                                                                constructor(parent: Context);
                                                                                                                                                                                • Create a REST application with the given parent context

                                                                                                                                                                                  Parameter parent

                                                                                                                                                                                  Parent context

                                                                                                                                                                                constructor

                                                                                                                                                                                constructor(config?: ApplicationConfig, parent?: Context);
                                                                                                                                                                                • Create a REST application with the given configuration and parent context

                                                                                                                                                                                  Parameter config

                                                                                                                                                                                  Application configuration

                                                                                                                                                                                  Parameter parent

                                                                                                                                                                                  Parent context

                                                                                                                                                                                property requestHandler

                                                                                                                                                                                readonly requestHandler: HttpRequestListener;
                                                                                                                                                                                • Handle incoming HTTP(S) request by invoking the corresponding Controller method via the configured Sequence.

                                                                                                                                                                                  Parameter req

                                                                                                                                                                                  The request.

                                                                                                                                                                                  Parameter res

                                                                                                                                                                                  The response.

                                                                                                                                                                                  Example 1

                                                                                                                                                                                  const app = new RestApplication();
                                                                                                                                                                                  // setup controllers, etc.
                                                                                                                                                                                  const server = http.createServer(app.requestHandler);
                                                                                                                                                                                  server.listen(3000);

                                                                                                                                                                                property restServer

                                                                                                                                                                                readonly restServer: RestServer;
                                                                                                                                                                                • The main REST server instance providing REST API for this application.

                                                                                                                                                                                method api

                                                                                                                                                                                api: (spec: OpenApiSpec) => Binding;
                                                                                                                                                                                • 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).

                                                                                                                                                                                  Parameter spec

                                                                                                                                                                                  The OpenAPI specification, as an object.

                                                                                                                                                                                  Returns

                                                                                                                                                                                  Binding for the api spec

                                                                                                                                                                                method basePath

                                                                                                                                                                                basePath: (path?: string) => void;
                                                                                                                                                                                • Configure the basePath for the rest server

                                                                                                                                                                                  Parameter path

                                                                                                                                                                                  Base path

                                                                                                                                                                                method bodyParser

                                                                                                                                                                                bodyParser: (
                                                                                                                                                                                bodyParserClass: Constructor<BodyParser>,
                                                                                                                                                                                address?: BindingAddress<BodyParser>
                                                                                                                                                                                ) => Binding<BodyParser>;
                                                                                                                                                                                • Bind a body parser to the server context

                                                                                                                                                                                  Parameter parserClass

                                                                                                                                                                                  Body parser class

                                                                                                                                                                                  Parameter address

                                                                                                                                                                                  Optional binding address

                                                                                                                                                                                method exportOpenApiSpec

                                                                                                                                                                                exportOpenApiSpec: (
                                                                                                                                                                                outFile?: string,
                                                                                                                                                                                log?: (message?: any, ...optionalParams: any[]) => void
                                                                                                                                                                                ) => Promise<void>;
                                                                                                                                                                                • Export the OpenAPI spec to the given json or yaml file

                                                                                                                                                                                  Parameter outFile

                                                                                                                                                                                  File name for the spec. The extension of the file determines the format of the file. - yaml or yml: YAML - json or other: JSON If the outFile is not provided or its value is '' or '-', the spec is written to the console using the log function.

                                                                                                                                                                                  Parameter log

                                                                                                                                                                                  Log function, default to console.log

                                                                                                                                                                                method expressMiddleware

                                                                                                                                                                                expressMiddleware: {
                                                                                                                                                                                (
                                                                                                                                                                                key: BindingAddress,
                                                                                                                                                                                middleware: ExpressRequestHandler | ExpressRequestHandler[],
                                                                                                                                                                                options?: MiddlewareBindingOptions
                                                                                                                                                                                ): Binding<Middleware>;
                                                                                                                                                                                <CFG>(
                                                                                                                                                                                middlewareFactory: ExpressMiddlewareFactory<CFG>,
                                                                                                                                                                                middlewareConfig?: CFG,
                                                                                                                                                                                options?: MiddlewareBindingOptions
                                                                                                                                                                                ): Binding<Middleware>;
                                                                                                                                                                                };
                                                                                                                                                                                • Bind an Express middleware to this server context

                                                                                                                                                                                  Parameter key

                                                                                                                                                                                  Middleware binding key

                                                                                                                                                                                  Parameter middleware

                                                                                                                                                                                  Express middleware handler function(s)

                                                                                                                                                                                  Example 1

                                                                                                                                                                                  import myExpressMiddlewareFactory from 'my-express-middleware';
                                                                                                                                                                                  const myExpressMiddlewareConfig= {};
                                                                                                                                                                                  const myExpressMiddleware = myExpressMiddlewareFactory(myExpressMiddlewareConfig);
                                                                                                                                                                                  server.expressMiddleware('middleware.express.my', myExpressMiddleware);
                                                                                                                                                                                • Bind an Express middleware to this server context

                                                                                                                                                                                  Parameter middlewareFactory

                                                                                                                                                                                  Middleware module name or factory function

                                                                                                                                                                                  Parameter middlewareConfig

                                                                                                                                                                                  Middleware config

                                                                                                                                                                                  Parameter options

                                                                                                                                                                                  Options for registration

                                                                                                                                                                                  Example 1

                                                                                                                                                                                  import myExpressMiddlewareFactory from 'my-express-middleware';
                                                                                                                                                                                  const myExpressMiddlewareConfig= {};
                                                                                                                                                                                  server.expressMiddleware(myExpressMiddlewareFactory, myExpressMiddlewareConfig);

                                                                                                                                                                                method handler

                                                                                                                                                                                handler: (handlerFn: SequenceFunction) => void;

                                                                                                                                                                                  method middleware

                                                                                                                                                                                  middleware: (
                                                                                                                                                                                  middleware: Middleware | Constructor<Provider<Middleware>>,
                                                                                                                                                                                  options?: MiddlewareBindingOptions
                                                                                                                                                                                  ) => Binding<Middleware>;
                                                                                                                                                                                  • Register a middleware function or provider class

                                                                                                                                                                                    Parameter middleware

                                                                                                                                                                                    Middleware function or provider class

                                                                                                                                                                                    Parameter options

                                                                                                                                                                                    Middleware binding options

                                                                                                                                                                                    Example 1

                                                                                                                                                                                    const log: Middleware = async (requestCtx, next) {
                                                                                                                                                                                    // ...
                                                                                                                                                                                    }
                                                                                                                                                                                    server.middleware(log);

                                                                                                                                                                                  method mountExpressRouter

                                                                                                                                                                                  mountExpressRouter: (
                                                                                                                                                                                  basePath: string,
                                                                                                                                                                                  router: ExpressRequestHandler,
                                                                                                                                                                                  spec?: RouterSpec
                                                                                                                                                                                  ) => void;
                                                                                                                                                                                  • Mount an Express router to expose additional REST endpoints handled via legacy Express-based stack.

                                                                                                                                                                                    Parameter basePath

                                                                                                                                                                                    Path where to mount the router at, e.g. / or /api.

                                                                                                                                                                                    Parameter router

                                                                                                                                                                                    The Express router to handle the requests.

                                                                                                                                                                                    Parameter spec

                                                                                                                                                                                    A partial OpenAPI spec describing endpoints provided by the router. LoopBack will prepend basePath to all endpoints automatically. This argument is optional. You can leave it out if you don't want to document the routes.

                                                                                                                                                                                  method redirect

                                                                                                                                                                                  redirect: (
                                                                                                                                                                                  fromPath: string,
                                                                                                                                                                                  toPathOrUrl: string,
                                                                                                                                                                                  statusCode?: number
                                                                                                                                                                                  ) => Binding;
                                                                                                                                                                                  • Register a route redirecting callers to a different URL.

                                                                                                                                                                                    Parameter fromPath

                                                                                                                                                                                    URL path of the redirect endpoint

                                                                                                                                                                                    Parameter toPathOrUrl

                                                                                                                                                                                    Location (URL path or full URL) where to redirect to. If your server is configured with a custom basePath, then the base path is prepended to the target location.

                                                                                                                                                                                    Parameter statusCode

                                                                                                                                                                                    HTTP status code to respond with, defaults to 303 (See Other).

                                                                                                                                                                                    Example 1

                                                                                                                                                                                    app.redirect('/explorer', '/explorer/');

                                                                                                                                                                                  method route

                                                                                                                                                                                  route: {
                                                                                                                                                                                  <T extends object>(
                                                                                                                                                                                  verb: string,
                                                                                                                                                                                  path: string,
                                                                                                                                                                                  spec: OperationObject,
                                                                                                                                                                                  controllerCtor: Constructor<T>,
                                                                                                                                                                                  controllerFactory: ControllerFactory<T>,
                                                                                                                                                                                  methodName: string
                                                                                                                                                                                  ): Binding;
                                                                                                                                                                                  (
                                                                                                                                                                                  verb: string,
                                                                                                                                                                                  path: string,
                                                                                                                                                                                  spec: OperationObject,
                                                                                                                                                                                  handler: Function
                                                                                                                                                                                  ): Binding;
                                                                                                                                                                                  (route: RouteEntry): Binding;
                                                                                                                                                                                  (
                                                                                                                                                                                  verb: string,
                                                                                                                                                                                  path: string,
                                                                                                                                                                                  spec: OperationObject,
                                                                                                                                                                                  handler: Function
                                                                                                                                                                                  ): Binding;
                                                                                                                                                                                  };
                                                                                                                                                                                  • Register a new Controller-based route.

                                                                                                                                                                                    Parameter verb

                                                                                                                                                                                    HTTP verb of the endpoint

                                                                                                                                                                                    Parameter path

                                                                                                                                                                                    URL path of the endpoint

                                                                                                                                                                                    Parameter spec

                                                                                                                                                                                    The OpenAPI spec describing the endpoint (operation)

                                                                                                                                                                                    Parameter controllerCtor

                                                                                                                                                                                    Controller constructor

                                                                                                                                                                                    Parameter controllerFactory

                                                                                                                                                                                    A factory function to create controller instance

                                                                                                                                                                                    Parameter methodName

                                                                                                                                                                                    The name of the controller method

                                                                                                                                                                                    Example 1

                                                                                                                                                                                    class MyController {
                                                                                                                                                                                    greet(name: string) {
                                                                                                                                                                                    return `hello ${name}`;
                                                                                                                                                                                    }
                                                                                                                                                                                    }
                                                                                                                                                                                    app.route('get', '/greet', operationSpec, MyController, 'greet');

                                                                                                                                                                                  • Register a new route invoking a handler function.

                                                                                                                                                                                    Parameter verb

                                                                                                                                                                                    HTTP verb of the endpoint

                                                                                                                                                                                    Parameter path

                                                                                                                                                                                    URL path of the endpoint

                                                                                                                                                                                    Parameter spec

                                                                                                                                                                                    The OpenAPI spec describing the endpoint (operation)

                                                                                                                                                                                    Parameter handler

                                                                                                                                                                                    The function to invoke with the request parameters described in the spec.

                                                                                                                                                                                    Example 1

                                                                                                                                                                                    function greet(name: string) {
                                                                                                                                                                                    return `hello ${name}`;
                                                                                                                                                                                    }
                                                                                                                                                                                    app.route('get', '/', operationSpec, greet);

                                                                                                                                                                                  • Register a new route.

                                                                                                                                                                                    Parameter route

                                                                                                                                                                                    The route to add.

                                                                                                                                                                                    Example 1

                                                                                                                                                                                    function greet(name: string) {
                                                                                                                                                                                    return `hello ${name}`;
                                                                                                                                                                                    }
                                                                                                                                                                                    const route = new Route('get', '/', operationSpec, greet);
                                                                                                                                                                                    app.route(route);

                                                                                                                                                                                  • Register a new route.

                                                                                                                                                                                    Example 1

                                                                                                                                                                                    function greet(name: string) {
                                                                                                                                                                                    return `hello ${name}`;
                                                                                                                                                                                    }
                                                                                                                                                                                    app.route('get', '/', operationSpec, greet);

                                                                                                                                                                                  method sequence

                                                                                                                                                                                  sequence: (sequence: Constructor<SequenceHandler>) => Binding;

                                                                                                                                                                                    method server

                                                                                                                                                                                    server: (server: Constructor<Server>, name?: string) => Binding;

                                                                                                                                                                                      method static

                                                                                                                                                                                      static: (
                                                                                                                                                                                      path: PathParams,
                                                                                                                                                                                      rootDir: string,
                                                                                                                                                                                      options?: ServeStaticOptions
                                                                                                                                                                                      ) => void;
                                                                                                                                                                                      • Mount static assets to the REST server. See https://expressjs.com/en/4x/api.html#express.static

                                                                                                                                                                                        Parameter path

                                                                                                                                                                                        The path(s) to serve the asset. See examples at https://expressjs.com/en/4x/api.html#path-examples To avoid performance penalty, / is not allowed for now.

                                                                                                                                                                                        Parameter rootDir

                                                                                                                                                                                        The root directory from which to serve static assets

                                                                                                                                                                                        Parameter options

                                                                                                                                                                                        Options for serve-static

                                                                                                                                                                                      class RestComponent

                                                                                                                                                                                      class RestComponent implements Component {}

                                                                                                                                                                                        constructor

                                                                                                                                                                                        constructor(app: Application, config?: any);

                                                                                                                                                                                          property bindings

                                                                                                                                                                                          bindings: Binding[];
                                                                                                                                                                                          • Add built-in body parsers

                                                                                                                                                                                          property providers

                                                                                                                                                                                          providers: ProviderMap;

                                                                                                                                                                                            property servers

                                                                                                                                                                                            servers: { [name: string]: Constructor<Server> };

                                                                                                                                                                                              class RestServer

                                                                                                                                                                                              class RestServer extends BaseMiddlewareRegistry implements Server, HttpServerLike {}
                                                                                                                                                                                              • A REST API server for use with Loopback. Add this server to your application by importing the RestComponent.

                                                                                                                                                                                                Example 1

                                                                                                                                                                                                const app = new MyApplication();
                                                                                                                                                                                                app.component(RestComponent);

                                                                                                                                                                                                To add additional instances of RestServer to your application, use the .server function:

                                                                                                                                                                                                app.server(RestServer, 'nameOfYourServer');

                                                                                                                                                                                                By default, one instance of RestServer will be created when the RestComponent is bootstrapped. This instance can be retrieved with app.getServer(RestServer), or by calling app.get('servers.RestServer') Note that retrieving other instances of RestServer must be done using the server's name:

                                                                                                                                                                                                const server = await app.getServer('foo')
                                                                                                                                                                                                // OR
                                                                                                                                                                                                const server = await app.get('servers.foo');

                                                                                                                                                                                              constructor

                                                                                                                                                                                              constructor(app: Application, config?: any);
                                                                                                                                                                                              • Creates an instance of RestServer.

                                                                                                                                                                                                Parameter app

                                                                                                                                                                                                The application instance (injected via CoreBindings.APPLICATION_INSTANCE).

                                                                                                                                                                                                Parameter config

                                                                                                                                                                                                The configuration options (injected via RestBindings.CONFIG).

                                                                                                                                                                                              property config

                                                                                                                                                                                              readonly config: any;

                                                                                                                                                                                                property httpHandler

                                                                                                                                                                                                readonly httpHandler: HttpHandler;

                                                                                                                                                                                                  property httpServer

                                                                                                                                                                                                  readonly httpServer: any;

                                                                                                                                                                                                    property listening

                                                                                                                                                                                                    readonly listening: boolean;

                                                                                                                                                                                                      property OASEnhancer

                                                                                                                                                                                                      readonly OASEnhancer: OASEnhancerService;

                                                                                                                                                                                                        property oasEnhancerService

                                                                                                                                                                                                        protected oasEnhancerService: OASEnhancerService;
                                                                                                                                                                                                        • Handle incoming HTTP(S) request by invoking the corresponding Controller method via the configured Sequence.

                                                                                                                                                                                                          Parameter req

                                                                                                                                                                                                          The request.

                                                                                                                                                                                                          Parameter res

                                                                                                                                                                                                          The response.

                                                                                                                                                                                                          Example 1

                                                                                                                                                                                                          const app = new Application();
                                                                                                                                                                                                          app.component(RestComponent);
                                                                                                                                                                                                          // setup controllers, etc.
                                                                                                                                                                                                          const restServer = await app.getServer(RestServer);
                                                                                                                                                                                                          const httpServer = http.createServer(restServer.requestHandler);
                                                                                                                                                                                                          httpServer.listen(3000);

                                                                                                                                                                                                        property requestHandler

                                                                                                                                                                                                        readonly requestHandler: HttpRequestListener;

                                                                                                                                                                                                          property rootUrl

                                                                                                                                                                                                          readonly rootUrl: string;
                                                                                                                                                                                                          • The root url for the server without the basePath. For example, the value will be 'http://localhost:3000' regardless of the basePath.

                                                                                                                                                                                                          property url

                                                                                                                                                                                                          readonly url: string;
                                                                                                                                                                                                          • The base url for the server, including the basePath if set. For example, the value will be 'http://localhost:3000/api' if basePath is set to '/api'.

                                                                                                                                                                                                          method addOpenApiSpecEndpoint

                                                                                                                                                                                                          addOpenApiSpecEndpoint: (
                                                                                                                                                                                                          path: string,
                                                                                                                                                                                                          form: OpenApiSpecForm,
                                                                                                                                                                                                          router?: express.Router
                                                                                                                                                                                                          ) => void;
                                                                                                                                                                                                          • Add a new non-controller endpoint hosting a form of the OpenAPI spec.

                                                                                                                                                                                                            Parameter path

                                                                                                                                                                                                            Path at which to host the copy of the OpenAPI

                                                                                                                                                                                                            Parameter form

                                                                                                                                                                                                            Form that should be rendered from that path

                                                                                                                                                                                                          method api

                                                                                                                                                                                                          api: (spec: OpenApiSpec) => Binding;
                                                                                                                                                                                                          • Set the OpenAPI specification that defines the REST API schema for this server. 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).

                                                                                                                                                                                                            Parameter spec

                                                                                                                                                                                                            The OpenAPI specification, as an object.

                                                                                                                                                                                                            Returns

                                                                                                                                                                                                            Binding for the spec

                                                                                                                                                                                                          method basePath

                                                                                                                                                                                                          basePath: (path?: string) => void;
                                                                                                                                                                                                          • Configure the basePath for the rest server

                                                                                                                                                                                                            Parameter path

                                                                                                                                                                                                            Base path

                                                                                                                                                                                                          method bodyParser

                                                                                                                                                                                                          bodyParser: (
                                                                                                                                                                                                          bodyParserClass: Constructor<BodyParser>,
                                                                                                                                                                                                          address?: BindingAddress<BodyParser>
                                                                                                                                                                                                          ) => Binding<BodyParser>;
                                                                                                                                                                                                          • Bind a body parser to the server context

                                                                                                                                                                                                            Parameter parserClass

                                                                                                                                                                                                            Body parser class

                                                                                                                                                                                                            Parameter address

                                                                                                                                                                                                            Optional binding address

                                                                                                                                                                                                          method controller

                                                                                                                                                                                                          controller: (controllerCtor: Constructor<T>) => Binding;
                                                                                                                                                                                                          • Register a controller class with this server.

                                                                                                                                                                                                            Parameter controllerCtor

                                                                                                                                                                                                            The controller class (constructor function).

                                                                                                                                                                                                            Returns

                                                                                                                                                                                                            The newly created binding, you can use the reference to further modify the binding, e.g. lock the value to prevent further modifications.

                                                                                                                                                                                                            Example 1

                                                                                                                                                                                                            class MyController {
                                                                                                                                                                                                            }
                                                                                                                                                                                                            app.controller(MyController).lock();

                                                                                                                                                                                                          method exportOpenApiSpec

                                                                                                                                                                                                          exportOpenApiSpec: (
                                                                                                                                                                                                          outFile?: string,
                                                                                                                                                                                                          log?: (message?: any, ...optionalParams: any[]) => void
                                                                                                                                                                                                          ) => Promise<void>;
                                                                                                                                                                                                          • Export the OpenAPI spec to the given json or yaml file

                                                                                                                                                                                                            Parameter outFile

                                                                                                                                                                                                            File name for the spec. The extension of the file determines the format of the file. - yaml or yml: YAML - json or other: JSON If the outFile is not provided or its value is '' or '-', the spec is written to the console using the log function.

                                                                                                                                                                                                            Parameter log

                                                                                                                                                                                                            Log function, default to console.log

                                                                                                                                                                                                          method getApiSpec

                                                                                                                                                                                                          getApiSpec: (requestContext?: RequestContext) => Promise<OpenApiSpec>;
                                                                                                                                                                                                          • Get the OpenAPI specification describing the REST API provided by this application.

                                                                                                                                                                                                            This method merges operations (HTTP endpoints) from the following sources: - app.api(spec) - app.controller(MyController) - app.route(route) - app.route('get', '/greet', operationSpec, MyController, 'greet')

                                                                                                                                                                                                            If the optional requestContext is provided, then the servers list in the returned spec will be updated to work in that context. Specifically: 1. if config.openApi.setServersFromRequest is enabled, the servers list will be replaced with the context base url 2. Any servers entries with a path of / will have that path replaced with requestContext.basePath

                                                                                                                                                                                                            Parameter requestContext

                                                                                                                                                                                                            Optional context to update the servers list in the returned spec

                                                                                                                                                                                                          method handler

                                                                                                                                                                                                          handler: (handlerFn: SequenceFunction) => void;
                                                                                                                                                                                                          • Configure a custom sequence function for handling incoming requests.

                                                                                                                                                                                                            Parameter handlerFn

                                                                                                                                                                                                            The handler to invoke for each incoming request.

                                                                                                                                                                                                            Example 1

                                                                                                                                                                                                            app.handler(({request, response}, sequence) => {
                                                                                                                                                                                                            sequence.send(response, 'hello world');
                                                                                                                                                                                                            });

                                                                                                                                                                                                          method mountExpressRouter

                                                                                                                                                                                                          mountExpressRouter: (
                                                                                                                                                                                                          basePath: string,
                                                                                                                                                                                                          router: ExpressRequestHandler,
                                                                                                                                                                                                          spec?: RouterSpec
                                                                                                                                                                                                          ) => void;
                                                                                                                                                                                                          • Mount an Express router to expose additional REST endpoints handled via legacy Express-based stack.

                                                                                                                                                                                                            Parameter basePath

                                                                                                                                                                                                            Path where to mount the router at, e.g. / or /api.

                                                                                                                                                                                                            Parameter router

                                                                                                                                                                                                            The Express router to handle the requests.

                                                                                                                                                                                                            Parameter spec

                                                                                                                                                                                                            A partial OpenAPI spec describing endpoints provided by the router. LoopBack will prepend basePath to all endpoints automatically. This argument is optional. You can leave it out if you don't want to document the routes.

                                                                                                                                                                                                          method redirect

                                                                                                                                                                                                          redirect: (
                                                                                                                                                                                                          fromPath: string,
                                                                                                                                                                                                          toPathOrUrl: string,
                                                                                                                                                                                                          statusCode?: number
                                                                                                                                                                                                          ) => Binding;
                                                                                                                                                                                                          • Register a route redirecting callers to a different URL.

                                                                                                                                                                                                            Parameter fromPath

                                                                                                                                                                                                            URL path of the redirect endpoint

                                                                                                                                                                                                            Parameter toPathOrUrl

                                                                                                                                                                                                            Location (URL path or full URL) where to redirect to. If your server is configured with a custom basePath, then the base path is prepended to the target location.

                                                                                                                                                                                                            Parameter statusCode

                                                                                                                                                                                                            HTTP status code to respond with, defaults to 303 (See Other).

                                                                                                                                                                                                            Example 1

                                                                                                                                                                                                            server.redirect('/explorer', '/explorer/');

                                                                                                                                                                                                          method route

                                                                                                                                                                                                          route: {
                                                                                                                                                                                                          <I extends object>(
                                                                                                                                                                                                          verb: string,
                                                                                                                                                                                                          path: string,
                                                                                                                                                                                                          spec: OperationObject,
                                                                                                                                                                                                          controllerCtor: Constructor<T>,
                                                                                                                                                                                                          controllerFactory: ControllerFactory<I>,
                                                                                                                                                                                                          methodName: string
                                                                                                                                                                                                          ): Binding;
                                                                                                                                                                                                          (
                                                                                                                                                                                                          verb: string,
                                                                                                                                                                                                          path: string,
                                                                                                                                                                                                          spec: OperationObject,
                                                                                                                                                                                                          handler: Function
                                                                                                                                                                                                          ): Binding;
                                                                                                                                                                                                          (route: RouteEntry): Binding;
                                                                                                                                                                                                          };
                                                                                                                                                                                                          • Register a new Controller-based route.

                                                                                                                                                                                                            Parameter verb

                                                                                                                                                                                                            HTTP verb of the endpoint

                                                                                                                                                                                                            Parameter path

                                                                                                                                                                                                            URL path of the endpoint

                                                                                                                                                                                                            Parameter spec

                                                                                                                                                                                                            The OpenAPI spec describing the endpoint (operation)

                                                                                                                                                                                                            Parameter controllerCtor

                                                                                                                                                                                                            Controller constructor

                                                                                                                                                                                                            Parameter controllerFactory

                                                                                                                                                                                                            A factory function to create controller instance

                                                                                                                                                                                                            Parameter methodName

                                                                                                                                                                                                            The name of the controller method

                                                                                                                                                                                                            Example 1

                                                                                                                                                                                                            class MyController {
                                                                                                                                                                                                            greet(name: string) {
                                                                                                                                                                                                            return `hello ${name}`;
                                                                                                                                                                                                            }
                                                                                                                                                                                                            }
                                                                                                                                                                                                            app.route('get', '/greet', operationSpec, MyController, 'greet');

                                                                                                                                                                                                          • Register a new route invoking a handler function.

                                                                                                                                                                                                            Parameter verb

                                                                                                                                                                                                            HTTP verb of the endpoint

                                                                                                                                                                                                            Parameter path

                                                                                                                                                                                                            URL path of the endpoint

                                                                                                                                                                                                            Parameter spec

                                                                                                                                                                                                            The OpenAPI spec describing the endpoint (operation)

                                                                                                                                                                                                            Parameter handler

                                                                                                                                                                                                            The function to invoke with the request parameters described in the spec.

                                                                                                                                                                                                            Example 1

                                                                                                                                                                                                            function greet(name: string) {
                                                                                                                                                                                                            return `hello ${name}`;
                                                                                                                                                                                                            }
                                                                                                                                                                                                            app.route('get', '/', operationSpec, greet);

                                                                                                                                                                                                          • Register a new generic route.

                                                                                                                                                                                                            Parameter route

                                                                                                                                                                                                            The route to add.

                                                                                                                                                                                                            Example 1

                                                                                                                                                                                                            function greet(name: string) {
                                                                                                                                                                                                            return `hello ${name}`;
                                                                                                                                                                                                            }
                                                                                                                                                                                                            const route = new Route('get', '/', operationSpec, greet);
                                                                                                                                                                                                            app.route(route);

                                                                                                                                                                                                          method sequence

                                                                                                                                                                                                          sequence: (
                                                                                                                                                                                                          sequenceClass: Constructor<SequenceHandler>
                                                                                                                                                                                                          ) => Binding<SequenceHandler>;
                                                                                                                                                                                                          • Configure a custom sequence class for handling incoming requests.

                                                                                                                                                                                                            Parameter sequenceClass

                                                                                                                                                                                                            The sequence class to invoke for each incoming request.

                                                                                                                                                                                                            Example 1

                                                                                                                                                                                                            class MySequence implements SequenceHandler {
                                                                                                                                                                                                            constructor(
                                                                                                                                                                                                            @inject('send) public send: Send)) {
                                                                                                                                                                                                            }
                                                                                                                                                                                                            public async handle({response}: RequestContext) {
                                                                                                                                                                                                            send(response, 'hello world');
                                                                                                                                                                                                            }
                                                                                                                                                                                                            }

                                                                                                                                                                                                          method start

                                                                                                                                                                                                          start: () => Promise<void>;
                                                                                                                                                                                                          • Start this REST API's HTTP/HTTPS server.

                                                                                                                                                                                                          method static

                                                                                                                                                                                                          static: (
                                                                                                                                                                                                          path: PathParams,
                                                                                                                                                                                                          rootDir: string,
                                                                                                                                                                                                          options?: ServeStaticOptions
                                                                                                                                                                                                          ) => void;
                                                                                                                                                                                                          • Mount static assets to the REST server. See https://expressjs.com/en/4x/api.html#express.static

                                                                                                                                                                                                            Parameter path

                                                                                                                                                                                                            The path(s) to serve the asset. See examples at https://expressjs.com/en/4x/api.html#path-examples

                                                                                                                                                                                                            Parameter rootDir

                                                                                                                                                                                                            The root directory from which to serve static assets

                                                                                                                                                                                                            Parameter options

                                                                                                                                                                                                            Options for serve-static

                                                                                                                                                                                                          method stop

                                                                                                                                                                                                          stop: () => Promise<void>;
                                                                                                                                                                                                          • Stop this REST API's HTTP/HTTPS server.

                                                                                                                                                                                                          class Route

                                                                                                                                                                                                          class Route extends BaseRoute {}

                                                                                                                                                                                                            constructor

                                                                                                                                                                                                            constructor(
                                                                                                                                                                                                            verb: string,
                                                                                                                                                                                                            path: string,
                                                                                                                                                                                                            spec: OperationObject,
                                                                                                                                                                                                            _handler: Function
                                                                                                                                                                                                            );

                                                                                                                                                                                                              property spec

                                                                                                                                                                                                              readonly spec: OperationObject;

                                                                                                                                                                                                                method describe

                                                                                                                                                                                                                describe: () => string;

                                                                                                                                                                                                                  method invokeHandler

                                                                                                                                                                                                                  invokeHandler: (
                                                                                                                                                                                                                  requestContext: Context,
                                                                                                                                                                                                                  args: OperationArgs
                                                                                                                                                                                                                  ) => Promise<OperationRetval>;

                                                                                                                                                                                                                    method updateBindings

                                                                                                                                                                                                                    updateBindings: (requestContext: Context) => void;

                                                                                                                                                                                                                      class RouteSource

                                                                                                                                                                                                                      class RouteSource implements InvocationSource<RouteEntry> {}

                                                                                                                                                                                                                        constructor

                                                                                                                                                                                                                        constructor(value: RouteEntry);

                                                                                                                                                                                                                          property type

                                                                                                                                                                                                                          type: string;

                                                                                                                                                                                                                            property value

                                                                                                                                                                                                                            readonly value: RouteEntry;

                                                                                                                                                                                                                              method toString

                                                                                                                                                                                                                              toString: () => string;

                                                                                                                                                                                                                                class RoutingTable

                                                                                                                                                                                                                                class RoutingTable {}
                                                                                                                                                                                                                                • Routing table

                                                                                                                                                                                                                                constructor

                                                                                                                                                                                                                                constructor(_router?: RestRouter, _externalRoutes?: ExternalExpressRoutes);

                                                                                                                                                                                                                                  method describeApiPaths

                                                                                                                                                                                                                                  describeApiPaths: () => PathObject;

                                                                                                                                                                                                                                    method find

                                                                                                                                                                                                                                    find: (request: Request) => ResolvedRoute;
                                                                                                                                                                                                                                    • Map a request to a route

                                                                                                                                                                                                                                      Parameter request

                                                                                                                                                                                                                                    method registerController

                                                                                                                                                                                                                                    registerController: <T extends object>(
                                                                                                                                                                                                                                    spec: ControllerSpec,
                                                                                                                                                                                                                                    controllerCtor: Constructor<T>,
                                                                                                                                                                                                                                    controllerFactory?: ControllerFactory<T>
                                                                                                                                                                                                                                    ) => void;
                                                                                                                                                                                                                                    • Register a controller as the route

                                                                                                                                                                                                                                      Parameter spec

                                                                                                                                                                                                                                      Parameter controllerCtor

                                                                                                                                                                                                                                      Parameter controllerFactory

                                                                                                                                                                                                                                    method registerRoute

                                                                                                                                                                                                                                    registerRoute: (route: RouteEntry) => void;
                                                                                                                                                                                                                                    • Register a route

                                                                                                                                                                                                                                      Parameter route

                                                                                                                                                                                                                                      A route entry

                                                                                                                                                                                                                                    class SendProvider

                                                                                                                                                                                                                                    class SendProvider {}
                                                                                                                                                                                                                                    • Provides the function that populates the response object with the results of the operation.

                                                                                                                                                                                                                                      Returns

                                                                                                                                                                                                                                      The handler function that will populate the response with operation results.

                                                                                                                                                                                                                                    method value

                                                                                                                                                                                                                                    static value: () => typeof writeResultToResponse;

                                                                                                                                                                                                                                      class SendResponseMiddlewareProvider

                                                                                                                                                                                                                                      class SendResponseMiddlewareProvider implements Provider<Middleware> {}

                                                                                                                                                                                                                                        method value

                                                                                                                                                                                                                                        value: () => Middleware;

                                                                                                                                                                                                                                          class StreamBodyParser

                                                                                                                                                                                                                                          class StreamBodyParser implements BodyParser {}
                                                                                                                                                                                                                                          • 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.

                                                                                                                                                                                                                                          property name

                                                                                                                                                                                                                                          name: Symbol;

                                                                                                                                                                                                                                            method parse

                                                                                                                                                                                                                                            parse: (request: Request) => Promise<RequestBody>;

                                                                                                                                                                                                                                              method supports

                                                                                                                                                                                                                                              supports: (mediaType: string) => boolean;

                                                                                                                                                                                                                                                class TextBodyParser

                                                                                                                                                                                                                                                class TextBodyParser implements BodyParser {}

                                                                                                                                                                                                                                                  constructor

                                                                                                                                                                                                                                                  constructor(options?: RequestBodyParserOptions);

                                                                                                                                                                                                                                                    property name

                                                                                                                                                                                                                                                    name: Symbol;

                                                                                                                                                                                                                                                      method parse

                                                                                                                                                                                                                                                      parse: (request: Request) => Promise<RequestBody>;

                                                                                                                                                                                                                                                        method supports

                                                                                                                                                                                                                                                        supports: (mediaType: string) => boolean;

                                                                                                                                                                                                                                                          class Trie

                                                                                                                                                                                                                                                          class Trie<T> {}
                                                                                                                                                                                                                                                          • An implementation of trie for routes. The key hierarchy is built with parts of the route path delimited by /

                                                                                                                                                                                                                                                          property root

                                                                                                                                                                                                                                                          readonly root: Node<T>;

                                                                                                                                                                                                                                                            method create

                                                                                                                                                                                                                                                            create: (routeTemplate: string, value: T) => Node<T>;
                                                                                                                                                                                                                                                            • Create a node for a given path template

                                                                                                                                                                                                                                                              Parameter pathTemplate

                                                                                                                                                                                                                                                              The path template,

                                                                                                                                                                                                                                                              Parameter value

                                                                                                                                                                                                                                                              Value of the route

                                                                                                                                                                                                                                                            method list

                                                                                                                                                                                                                                                            list: () => NodeWithValue<T>[];
                                                                                                                                                                                                                                                            • List all nodes with value of the trie

                                                                                                                                                                                                                                                            method match

                                                                                                                                                                                                                                                            match: (
                                                                                                                                                                                                                                                            path: string
                                                                                                                                                                                                                                                            ) => (ResolvedNode<T> & { node: NodeWithValue<T> }) | undefined;
                                                                                                                                                                                                                                                            • Match a route path against the trie

                                                                                                                                                                                                                                                              Parameter path

                                                                                                                                                                                                                                                              The route path, such as /customers/c01

                                                                                                                                                                                                                                                            class TrieRouter

                                                                                                                                                                                                                                                            class TrieRouter extends BaseRouter {}
                                                                                                                                                                                                                                                            • Router implementation based on trie

                                                                                                                                                                                                                                                            constructor

                                                                                                                                                                                                                                                            constructor(options?: RestRouterOptions);

                                                                                                                                                                                                                                                              method addRouteWithPathVars

                                                                                                                                                                                                                                                              protected addRouteWithPathVars: (route: RouteEntry) => void;

                                                                                                                                                                                                                                                                method findRouteWithPathVars

                                                                                                                                                                                                                                                                protected findRouteWithPathVars: (
                                                                                                                                                                                                                                                                verb: string,
                                                                                                                                                                                                                                                                path: string
                                                                                                                                                                                                                                                                ) => ResolvedRoute | undefined;

                                                                                                                                                                                                                                                                  method listRoutesWithPathVars

                                                                                                                                                                                                                                                                  protected listRoutesWithPathVars: () => RouteEntry[];

                                                                                                                                                                                                                                                                    class UrlEncodedBodyParser

                                                                                                                                                                                                                                                                    class UrlEncodedBodyParser implements BodyParser {}

                                                                                                                                                                                                                                                                      constructor

                                                                                                                                                                                                                                                                      constructor(options?: RequestBodyParserOptions);

                                                                                                                                                                                                                                                                        property name

                                                                                                                                                                                                                                                                        name: Symbol;

                                                                                                                                                                                                                                                                          method parse

                                                                                                                                                                                                                                                                          parse: (request: Request) => Promise<RequestBody>;

                                                                                                                                                                                                                                                                            method supports

                                                                                                                                                                                                                                                                            supports: (mediaType: string) => boolean;

                                                                                                                                                                                                                                                                              Interfaces

                                                                                                                                                                                                                                                                              interface ApiExplorerOptions

                                                                                                                                                                                                                                                                              interface ApiExplorerOptions {}

                                                                                                                                                                                                                                                                                property disabled

                                                                                                                                                                                                                                                                                disabled?: true;
                                                                                                                                                                                                                                                                                • Set this flag to disable the built-in redirect to externally hosted API Explorer UI.

                                                                                                                                                                                                                                                                                property httpUrl

                                                                                                                                                                                                                                                                                httpUrl?: string;
                                                                                                                                                                                                                                                                                • URL for the API explorer served over http protocol to deal with mixed content security imposed by browsers as the spec is exposed over http by default. See https://github.com/loopbackio/loopback-next/issues/1603

                                                                                                                                                                                                                                                                                property url

                                                                                                                                                                                                                                                                                url?: string;
                                                                                                                                                                                                                                                                                • URL for the hosted API explorer UI default to https://loopback.io/api-explorer

                                                                                                                                                                                                                                                                                interface BodyParser

                                                                                                                                                                                                                                                                                interface BodyParser {}
                                                                                                                                                                                                                                                                                • Interface to be implemented by body parser extensions

                                                                                                                                                                                                                                                                                property name

                                                                                                                                                                                                                                                                                name: string | symbol;
                                                                                                                                                                                                                                                                                • Name of the parser

                                                                                                                                                                                                                                                                                method parse

                                                                                                                                                                                                                                                                                parse: (request: Request) => Promise<RequestBody>;
                                                                                                                                                                                                                                                                                • Parse the request body

                                                                                                                                                                                                                                                                                  Parameter request

                                                                                                                                                                                                                                                                                  http request

                                                                                                                                                                                                                                                                                method supports

                                                                                                                                                                                                                                                                                supports: (mediaType: string) => boolean;
                                                                                                                                                                                                                                                                                • Indicate if the given media type is supported

                                                                                                                                                                                                                                                                                  Parameter mediaType

                                                                                                                                                                                                                                                                                  Media type

                                                                                                                                                                                                                                                                                interface HttpServerLike

                                                                                                                                                                                                                                                                                interface HttpServerLike {}

                                                                                                                                                                                                                                                                                  property requestHandler

                                                                                                                                                                                                                                                                                  requestHandler: HttpRequestListener;

                                                                                                                                                                                                                                                                                    interface Node

                                                                                                                                                                                                                                                                                    interface Node<T> {}
                                                                                                                                                                                                                                                                                    • A Node in the trie

                                                                                                                                                                                                                                                                                    property children

                                                                                                                                                                                                                                                                                    readonly children: {
                                                                                                                                                                                                                                                                                    [key: string]: Node<T>;
                                                                                                                                                                                                                                                                                    };
                                                                                                                                                                                                                                                                                    • Children of the node

                                                                                                                                                                                                                                                                                    property key

                                                                                                                                                                                                                                                                                    key: string;
                                                                                                                                                                                                                                                                                    • Key of the node

                                                                                                                                                                                                                                                                                    property names

                                                                                                                                                                                                                                                                                    names?: string[];
                                                                                                                                                                                                                                                                                    • Names of the node if it contains named parameters

                                                                                                                                                                                                                                                                                    property regexp

                                                                                                                                                                                                                                                                                    regexp?: RegExp;
                                                                                                                                                                                                                                                                                    • Regular expression for the template

                                                                                                                                                                                                                                                                                    property value

                                                                                                                                                                                                                                                                                    value?: T;
                                                                                                                                                                                                                                                                                    • Value of the node

                                                                                                                                                                                                                                                                                    interface OpenApiSpecForm

                                                                                                                                                                                                                                                                                    interface OpenApiSpecForm {}
                                                                                                                                                                                                                                                                                    • The form of OpenAPI specs to be served

                                                                                                                                                                                                                                                                                    property format

                                                                                                                                                                                                                                                                                    format?: string;

                                                                                                                                                                                                                                                                                      property version

                                                                                                                                                                                                                                                                                      version?: string;

                                                                                                                                                                                                                                                                                        interface OpenApiSpecOptions

                                                                                                                                                                                                                                                                                        interface OpenApiSpecOptions {}
                                                                                                                                                                                                                                                                                        • Options to customize how OpenAPI specs are served

                                                                                                                                                                                                                                                                                        property consolidate

                                                                                                                                                                                                                                                                                        consolidate?: boolean;
                                                                                                                                                                                                                                                                                        • Set this flag to false to disable OAS schema consolidation. If not set, the value defaults to true.

                                                                                                                                                                                                                                                                                        property disabled

                                                                                                                                                                                                                                                                                        disabled?: true;
                                                                                                                                                                                                                                                                                        • Set this flag to disable the endpoint for OpenAPI spec

                                                                                                                                                                                                                                                                                        property endpointMapping

                                                                                                                                                                                                                                                                                        endpointMapping?: {
                                                                                                                                                                                                                                                                                        [key: string]: OpenApiSpecForm;
                                                                                                                                                                                                                                                                                        };
                                                                                                                                                                                                                                                                                        • Mapping of urls to spec forms, by default: { '/openapi.json': {version: '3.0.0', format: 'json'}, '/openapi.yaml': {version: '3.0.0', format: 'yaml'}, }

                                                                                                                                                                                                                                                                                        property servers

                                                                                                                                                                                                                                                                                        servers?: ServerObject[];
                                                                                                                                                                                                                                                                                        • Configure servers for OpenAPI spec

                                                                                                                                                                                                                                                                                        property setServersFromRequest

                                                                                                                                                                                                                                                                                        setServersFromRequest?: boolean;
                                                                                                                                                                                                                                                                                        • A flag to force servers to be set from the http request for the OpenAPI spec

                                                                                                                                                                                                                                                                                        interface RequestBodyParserOptions

                                                                                                                                                                                                                                                                                        interface RequestBodyParserOptions extends Options {}
                                                                                                                                                                                                                                                                                        • 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.

                                                                                                                                                                                                                                                                                        property json

                                                                                                                                                                                                                                                                                        json?: OptionsJson;
                                                                                                                                                                                                                                                                                        • Options for json parser

                                                                                                                                                                                                                                                                                        property raw

                                                                                                                                                                                                                                                                                        raw?: Options;
                                                                                                                                                                                                                                                                                        • Options for raw parser

                                                                                                                                                                                                                                                                                        property text

                                                                                                                                                                                                                                                                                        text?: OptionsText;
                                                                                                                                                                                                                                                                                        • Options for text parser

                                                                                                                                                                                                                                                                                        property urlencoded

                                                                                                                                                                                                                                                                                        urlencoded?: OptionsUrlencoded;
                                                                                                                                                                                                                                                                                        • Options for urlencoded parser

                                                                                                                                                                                                                                                                                        property validation

                                                                                                                                                                                                                                                                                        validation?: ValidationOptions;
                                                                                                                                                                                                                                                                                        • Validation options for AJV, see https://github.com/epoberezkin/ajv#options This setting is global for all request body parsers and it cannot be overridden inside parser specific properties such as json or text.

                                                                                                                                                                                                                                                                                        index signature

                                                                                                                                                                                                                                                                                        [name: string]: unknown;
                                                                                                                                                                                                                                                                                        • Common options for all parsers

                                                                                                                                                                                                                                                                                        interface RequestWithSession

                                                                                                                                                                                                                                                                                        interface RequestWithSession extends Request {}
                                                                                                                                                                                                                                                                                        • extending express request type with a session field

                                                                                                                                                                                                                                                                                        property session

                                                                                                                                                                                                                                                                                        session: Session;

                                                                                                                                                                                                                                                                                          interface ResolvedNode

                                                                                                                                                                                                                                                                                          interface ResolvedNode<T> {}

                                                                                                                                                                                                                                                                                            property node

                                                                                                                                                                                                                                                                                            node: Node<T>;

                                                                                                                                                                                                                                                                                              property params

                                                                                                                                                                                                                                                                                              params?: PathParameterValues;

                                                                                                                                                                                                                                                                                                interface ResolvedRoute

                                                                                                                                                                                                                                                                                                interface ResolvedRoute extends RouteEntry {}
                                                                                                                                                                                                                                                                                                • A route with path parameters resolved

                                                                                                                                                                                                                                                                                                property pathParams

                                                                                                                                                                                                                                                                                                readonly pathParams: PathParameterValues;

                                                                                                                                                                                                                                                                                                  property schemas

                                                                                                                                                                                                                                                                                                  readonly schemas: SchemasObject;
                                                                                                                                                                                                                                                                                                  • Server/application wide schemas shared by multiple routes, e.g. model schemas. This is a temporary workaround for missing support for $ref references, see https://github.com/loopbackio/loopback-next/issues/435

                                                                                                                                                                                                                                                                                                  interface RestRouter

                                                                                                                                                                                                                                                                                                  interface RestRouter {}

                                                                                                                                                                                                                                                                                                    method add

                                                                                                                                                                                                                                                                                                    add: (route: RouteEntry) => void;
                                                                                                                                                                                                                                                                                                    • Add a route to the router

                                                                                                                                                                                                                                                                                                      Parameter route

                                                                                                                                                                                                                                                                                                      A route entry

                                                                                                                                                                                                                                                                                                    method find

                                                                                                                                                                                                                                                                                                    find: (request: Request) => ResolvedRoute | undefined;
                                                                                                                                                                                                                                                                                                    • Find a matching route for the given http request

                                                                                                                                                                                                                                                                                                      Parameter request

                                                                                                                                                                                                                                                                                                      Http request

                                                                                                                                                                                                                                                                                                      Returns

                                                                                                                                                                                                                                                                                                      The resolved route, if not found, undefined is returned

                                                                                                                                                                                                                                                                                                    method list

                                                                                                                                                                                                                                                                                                    list: () => RouteEntry[];
                                                                                                                                                                                                                                                                                                    • List all routes

                                                                                                                                                                                                                                                                                                    interface RestServerResolvedOptions

                                                                                                                                                                                                                                                                                                    interface RestServerResolvedOptions {}

                                                                                                                                                                                                                                                                                                      property apiExplorer

                                                                                                                                                                                                                                                                                                      apiExplorer: ApiExplorerOptions;

                                                                                                                                                                                                                                                                                                        property basePath

                                                                                                                                                                                                                                                                                                        basePath?: string;
                                                                                                                                                                                                                                                                                                        • Base path for API/static routes

                                                                                                                                                                                                                                                                                                        property cors

                                                                                                                                                                                                                                                                                                        cors: cors.CorsOptions;

                                                                                                                                                                                                                                                                                                          property expressSettings

                                                                                                                                                                                                                                                                                                          expressSettings: {
                                                                                                                                                                                                                                                                                                          [name: string]: any;
                                                                                                                                                                                                                                                                                                          };

                                                                                                                                                                                                                                                                                                            property listenOnStart

                                                                                                                                                                                                                                                                                                            listenOnStart?: boolean;
                                                                                                                                                                                                                                                                                                            • Set this flag to false to not listen on connections when the REST server is started. It's useful to mount a LoopBack REST server as a route to the facade Express application. If not set, the value is default to true.

                                                                                                                                                                                                                                                                                                            property openApiSpec

                                                                                                                                                                                                                                                                                                            openApiSpec: OpenApiSpecOptions;

                                                                                                                                                                                                                                                                                                              property path

                                                                                                                                                                                                                                                                                                              path?: string;

                                                                                                                                                                                                                                                                                                                property port

                                                                                                                                                                                                                                                                                                                port: number;

                                                                                                                                                                                                                                                                                                                  property requestBodyParser

                                                                                                                                                                                                                                                                                                                  requestBodyParser?: RequestBodyParserOptions;

                                                                                                                                                                                                                                                                                                                    property router

                                                                                                                                                                                                                                                                                                                    router: RestRouterOptions;

                                                                                                                                                                                                                                                                                                                      property sequence

                                                                                                                                                                                                                                                                                                                      sequence?: Constructor<SequenceHandler>;

                                                                                                                                                                                                                                                                                                                        interface RouteEntry

                                                                                                                                                                                                                                                                                                                        interface RouteEntry {}
                                                                                                                                                                                                                                                                                                                        • An entry in the routing table

                                                                                                                                                                                                                                                                                                                        property path

                                                                                                                                                                                                                                                                                                                        readonly path: string;
                                                                                                                                                                                                                                                                                                                        • http path

                                                                                                                                                                                                                                                                                                                        property spec

                                                                                                                                                                                                                                                                                                                        readonly spec: OperationObject;
                                                                                                                                                                                                                                                                                                                        • OpenAPI operation spec

                                                                                                                                                                                                                                                                                                                        property verb

                                                                                                                                                                                                                                                                                                                        readonly verb: string;
                                                                                                                                                                                                                                                                                                                        • http verb

                                                                                                                                                                                                                                                                                                                        method describe

                                                                                                                                                                                                                                                                                                                        describe: () => string;

                                                                                                                                                                                                                                                                                                                          method invokeHandler

                                                                                                                                                                                                                                                                                                                          invokeHandler: (
                                                                                                                                                                                                                                                                                                                          requestContext: Context,
                                                                                                                                                                                                                                                                                                                          args: OperationArgs
                                                                                                                                                                                                                                                                                                                          ) => Promise<OperationRetval>;
                                                                                                                                                                                                                                                                                                                          • A handler to invoke the resolved controller method

                                                                                                                                                                                                                                                                                                                            Parameter requestContext

                                                                                                                                                                                                                                                                                                                            Parameter args

                                                                                                                                                                                                                                                                                                                          method updateBindings

                                                                                                                                                                                                                                                                                                                          updateBindings: (requestContext: Context) => void;
                                                                                                                                                                                                                                                                                                                          • Update bindings for the request context

                                                                                                                                                                                                                                                                                                                            Parameter requestContext

                                                                                                                                                                                                                                                                                                                          interface SequenceHandler

                                                                                                                                                                                                                                                                                                                          interface SequenceHandler {}
                                                                                                                                                                                                                                                                                                                          • A sequence handler is a class implementing sequence of actions required to handle an incoming request.

                                                                                                                                                                                                                                                                                                                          method handle

                                                                                                                                                                                                                                                                                                                          handle: (context: RequestContext) => Promise<void>;
                                                                                                                                                                                                                                                                                                                          • Handle the request by running the configured sequence of actions.

                                                                                                                                                                                                                                                                                                                            Parameter context

                                                                                                                                                                                                                                                                                                                            The request context: HTTP request and response objects, per-request IoC container and more.

                                                                                                                                                                                                                                                                                                                          interface Session

                                                                                                                                                                                                                                                                                                                          interface Session {}
                                                                                                                                                                                                                                                                                                                          • interface to set variables in user session

                                                                                                                                                                                                                                                                                                                          property profile

                                                                                                                                                                                                                                                                                                                          profile: SessionUserProfile;

                                                                                                                                                                                                                                                                                                                            index signature

                                                                                                                                                                                                                                                                                                                            [key: string]: any;

                                                                                                                                                                                                                                                                                                                              interface SessionUserProfile

                                                                                                                                                                                                                                                                                                                              interface SessionUserProfile {}
                                                                                                                                                                                                                                                                                                                              • user profile to add in session

                                                                                                                                                                                                                                                                                                                              property email

                                                                                                                                                                                                                                                                                                                              email: string;

                                                                                                                                                                                                                                                                                                                                property provider

                                                                                                                                                                                                                                                                                                                                provider: string;

                                                                                                                                                                                                                                                                                                                                  property token

                                                                                                                                                                                                                                                                                                                                  token: string;

                                                                                                                                                                                                                                                                                                                                    index signature

                                                                                                                                                                                                                                                                                                                                    [attribute: string]: any;

                                                                                                                                                                                                                                                                                                                                      interface ValidationOptions

                                                                                                                                                                                                                                                                                                                                      interface ValidationOptions extends AjvOptions {}
                                                                                                                                                                                                                                                                                                                                      • Options for request body validation using AJV

                                                                                                                                                                                                                                                                                                                                      property ajvErrors

                                                                                                                                                                                                                                                                                                                                      ajvErrors?: AjvErrorOptions;
                                                                                                                                                                                                                                                                                                                                      • Enable custom error messages in JSON-Schema for AJV validator from https://github.com/epoberezkin/ajv-errors - true: Enable ajv-errors - AjvErrorOptions: Enable ajv-errors with options

                                                                                                                                                                                                                                                                                                                                      property ajvErrorTransformer

                                                                                                                                                                                                                                                                                                                                      ajvErrorTransformer?: (errors: ErrorObject[]) => ErrorObject[];
                                                                                                                                                                                                                                                                                                                                      • A function that transform the ErrorObjects reported by AJV. This could be used for error messages customization, localization, etc.

                                                                                                                                                                                                                                                                                                                                      property ajvFactory

                                                                                                                                                                                                                                                                                                                                      ajvFactory?: (options: AjvOptions) => Ajv;
                                                                                                                                                                                                                                                                                                                                      • A factory to create Ajv instance

                                                                                                                                                                                                                                                                                                                                      property ajvKeywords

                                                                                                                                                                                                                                                                                                                                      ajvKeywords?: string[];
                                                                                                                                                                                                                                                                                                                                      • Enable additional AJV keywords from https://github.com/epoberezkin/ajv-keywords - string[]: Add an array of keywords from ajv-keywords

                                                                                                                                                                                                                                                                                                                                      property compiledSchemaCache

                                                                                                                                                                                                                                                                                                                                      compiledSchemaCache?: SchemaValidatorCache;
                                                                                                                                                                                                                                                                                                                                      • Custom cache for compiled schemas by AJV. This setting makes it possible to skip the default cache.

                                                                                                                                                                                                                                                                                                                                      property prohibitedKeys

                                                                                                                                                                                                                                                                                                                                      prohibitedKeys?: string[];
                                                                                                                                                                                                                                                                                                                                      • An array of keys to be rejected, such as __proto__.

                                                                                                                                                                                                                                                                                                                                      interface ValueValidationOptions

                                                                                                                                                                                                                                                                                                                                      interface ValueValidationOptions extends ValidationOptions {}
                                                                                                                                                                                                                                                                                                                                      • Options for any value validation using AJV

                                                                                                                                                                                                                                                                                                                                      property name

                                                                                                                                                                                                                                                                                                                                      name?: string;
                                                                                                                                                                                                                                                                                                                                      • Parameter name, as provided in ParameterObject#name property.

                                                                                                                                                                                                                                                                                                                                      property source

                                                                                                                                                                                                                                                                                                                                      source?: string;
                                                                                                                                                                                                                                                                                                                                      • Where the data comes from. It can be 'body', 'path', 'header', 'query', 'cookie', etc...

                                                                                                                                                                                                                                                                                                                                      Type Aliases

                                                                                                                                                                                                                                                                                                                                      type AjvErrorOptions

                                                                                                                                                                                                                                                                                                                                      type AjvErrorOptions = ErrorMessageOptions;
                                                                                                                                                                                                                                                                                                                                      • Options for AJV errors

                                                                                                                                                                                                                                                                                                                                      type AjvFactory

                                                                                                                                                                                                                                                                                                                                      type AjvFactory = (options?: AjvOptions) => Ajv;
                                                                                                                                                                                                                                                                                                                                      • Factory function for Ajv instances

                                                                                                                                                                                                                                                                                                                                      type AjvFormat

                                                                                                                                                                                                                                                                                                                                      type AjvFormat<T extends string | number = string> = FormatDefinition<T> & {
                                                                                                                                                                                                                                                                                                                                      name: string;
                                                                                                                                                                                                                                                                                                                                      };
                                                                                                                                                                                                                                                                                                                                      • Ajv format definition with a name

                                                                                                                                                                                                                                                                                                                                      type AjvKeyword

                                                                                                                                                                                                                                                                                                                                      type AjvKeyword = KeywordDefinition;
                                                                                                                                                                                                                                                                                                                                      • Ajv keyword definition with a name

                                                                                                                                                                                                                                                                                                                                      type BodyParserFunction

                                                                                                                                                                                                                                                                                                                                      type BodyParserFunction = (request: Request) => Promise<RequestBody>;
                                                                                                                                                                                                                                                                                                                                      • Plain function for body parsing

                                                                                                                                                                                                                                                                                                                                      type BodyParserMiddleware

                                                                                                                                                                                                                                                                                                                                      type BodyParserMiddleware = (
                                                                                                                                                                                                                                                                                                                                      request: Request,
                                                                                                                                                                                                                                                                                                                                      response: Response,
                                                                                                                                                                                                                                                                                                                                      next: (err: HttpError) => void
                                                                                                                                                                                                                                                                                                                                      ) => void;
                                                                                                                                                                                                                                                                                                                                      • Express body parser function type

                                                                                                                                                                                                                                                                                                                                      type ControllerClass

                                                                                                                                                                                                                                                                                                                                      type ControllerClass<T extends ControllerInstance> = Constructor<T>;
                                                                                                                                                                                                                                                                                                                                      • Controller class

                                                                                                                                                                                                                                                                                                                                      type ControllerFactory

                                                                                                                                                                                                                                                                                                                                      type ControllerFactory<T extends ControllerInstance> = (
                                                                                                                                                                                                                                                                                                                                      ctx: Context
                                                                                                                                                                                                                                                                                                                                      ) => ValueOrPromise<T>;
                                                                                                                                                                                                                                                                                                                                      • A factory function to create controller instances synchronously or asynchronously

                                                                                                                                                                                                                                                                                                                                      type ControllerInstance

                                                                                                                                                                                                                                                                                                                                      type ControllerInstance = {
                                                                                                                                                                                                                                                                                                                                      [name: string]: any;
                                                                                                                                                                                                                                                                                                                                      } & object;

                                                                                                                                                                                                                                                                                                                                        type FindRoute

                                                                                                                                                                                                                                                                                                                                        type FindRoute = (request: Request) => ResolvedRoute;
                                                                                                                                                                                                                                                                                                                                        • Find a route matching the incoming request. Throw an error when no route was found.

                                                                                                                                                                                                                                                                                                                                        type HttpRequestListener

                                                                                                                                                                                                                                                                                                                                        type HttpRequestListener = (req: IncomingMessage, res: ServerResponse) => void;

                                                                                                                                                                                                                                                                                                                                          type InvokeMethod

                                                                                                                                                                                                                                                                                                                                          type InvokeMethod = (
                                                                                                                                                                                                                                                                                                                                          route: RouteEntry,
                                                                                                                                                                                                                                                                                                                                          args: OperationArgs
                                                                                                                                                                                                                                                                                                                                          ) => Promise<OperationRetval>;
                                                                                                                                                                                                                                                                                                                                          • Invokes a method defined in the Application Controller

                                                                                                                                                                                                                                                                                                                                            Parameter controller

                                                                                                                                                                                                                                                                                                                                            Name of end-user's application controller class which defines the methods.

                                                                                                                                                                                                                                                                                                                                            Parameter method

                                                                                                                                                                                                                                                                                                                                            Method name in application controller class

                                                                                                                                                                                                                                                                                                                                            Parameter args

                                                                                                                                                                                                                                                                                                                                            Operation arguments for the method

                                                                                                                                                                                                                                                                                                                                            Returns

                                                                                                                                                                                                                                                                                                                                            OperationRetval Result from method invocation

                                                                                                                                                                                                                                                                                                                                          type LogError

                                                                                                                                                                                                                                                                                                                                          type LogError = (err: Error, statusCode: number, request: Request) => void;
                                                                                                                                                                                                                                                                                                                                          • Log information about a failed request.

                                                                                                                                                                                                                                                                                                                                            Parameter err

                                                                                                                                                                                                                                                                                                                                            The error reported by request handling code.

                                                                                                                                                                                                                                                                                                                                            Parameter statusCode

                                                                                                                                                                                                                                                                                                                                            Status code of the HTTP response

                                                                                                                                                                                                                                                                                                                                            Parameter request

                                                                                                                                                                                                                                                                                                                                            The request that failed.

                                                                                                                                                                                                                                                                                                                                          type NodeWithValue

                                                                                                                                                                                                                                                                                                                                          type NodeWithValue<T> = Node<T> & {
                                                                                                                                                                                                                                                                                                                                          value: T;
                                                                                                                                                                                                                                                                                                                                          };

                                                                                                                                                                                                                                                                                                                                            type OperationArgs

                                                                                                                                                                                                                                                                                                                                            type OperationArgs = any[];

                                                                                                                                                                                                                                                                                                                                              type OperationRetval

                                                                                                                                                                                                                                                                                                                                              type OperationRetval = any;
                                                                                                                                                                                                                                                                                                                                              • 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.

                                                                                                                                                                                                                                                                                                                                              type ParseParams

                                                                                                                                                                                                                                                                                                                                              type ParseParams = (
                                                                                                                                                                                                                                                                                                                                              request: Request,
                                                                                                                                                                                                                                                                                                                                              route: ResolvedRoute
                                                                                                                                                                                                                                                                                                                                              ) => Promise<OperationArgs>;
                                                                                                                                                                                                                                                                                                                                              • A function to parse OpenAPI operation parameters for a given route

                                                                                                                                                                                                                                                                                                                                              type PathParameterValues

                                                                                                                                                                                                                                                                                                                                              type PathParameterValues = {
                                                                                                                                                                                                                                                                                                                                              [key: string]: any;
                                                                                                                                                                                                                                                                                                                                              };

                                                                                                                                                                                                                                                                                                                                                type Reject

                                                                                                                                                                                                                                                                                                                                                type Reject = (handlerContext: HandlerContext, err: Error) => void;
                                                                                                                                                                                                                                                                                                                                                • Reject the request with an error.

                                                                                                                                                                                                                                                                                                                                                  Parameter handlerContext

                                                                                                                                                                                                                                                                                                                                                  The context object holding HTTP request, response and other data needed to handle an incoming HTTP request.

                                                                                                                                                                                                                                                                                                                                                  Parameter err

                                                                                                                                                                                                                                                                                                                                                  The error.

                                                                                                                                                                                                                                                                                                                                                type RequestBody

                                                                                                                                                                                                                                                                                                                                                type RequestBody = {
                                                                                                                                                                                                                                                                                                                                                /**
                                                                                                                                                                                                                                                                                                                                                * Parsed value of the request body
                                                                                                                                                                                                                                                                                                                                                */
                                                                                                                                                                                                                                                                                                                                                value: any | undefined;
                                                                                                                                                                                                                                                                                                                                                /**
                                                                                                                                                                                                                                                                                                                                                * Is coercion required? Some forms of request such as urlencoded don't
                                                                                                                                                                                                                                                                                                                                                * have rich types such as number or boolean.
                                                                                                                                                                                                                                                                                                                                                */
                                                                                                                                                                                                                                                                                                                                                coercionRequired?: boolean;
                                                                                                                                                                                                                                                                                                                                                /**
                                                                                                                                                                                                                                                                                                                                                * Resolved media type
                                                                                                                                                                                                                                                                                                                                                */
                                                                                                                                                                                                                                                                                                                                                mediaType?: string;
                                                                                                                                                                                                                                                                                                                                                /**
                                                                                                                                                                                                                                                                                                                                                * Corresponding schema for the request body
                                                                                                                                                                                                                                                                                                                                                */
                                                                                                                                                                                                                                                                                                                                                schema?: SchemaObject | ReferenceObject;
                                                                                                                                                                                                                                                                                                                                                };
                                                                                                                                                                                                                                                                                                                                                • Request body with metadata

                                                                                                                                                                                                                                                                                                                                                type RequestBodyValidationOptions

                                                                                                                                                                                                                                                                                                                                                type RequestBodyValidationOptions = ValidationOptions;

                                                                                                                                                                                                                                                                                                                                                  type RestComponentConfig

                                                                                                                                                                                                                                                                                                                                                  type RestComponentConfig = RestServerConfig;

                                                                                                                                                                                                                                                                                                                                                    type RestRouterOptions

                                                                                                                                                                                                                                                                                                                                                    type RestRouterOptions = {
                                                                                                                                                                                                                                                                                                                                                    /**
                                                                                                                                                                                                                                                                                                                                                    * When `true` it uses trailing slash to match. (default: `false`)
                                                                                                                                                                                                                                                                                                                                                    *
                                                                                                                                                                                                                                                                                                                                                    * 1. `strict` is true:
                                                                                                                                                                                                                                                                                                                                                    * - request `/orders` matches route `/orders` but not `/orders/`
                                                                                                                                                                                                                                                                                                                                                    * - request `/orders/` matches route `/orders/` but not `/orders`
                                                                                                                                                                                                                                                                                                                                                    *
                                                                                                                                                                                                                                                                                                                                                    * 2. `strict` is false (default)
                                                                                                                                                                                                                                                                                                                                                    * - request `/orders` matches route `/orders` first and falls back to `/orders/`
                                                                                                                                                                                                                                                                                                                                                    * - request `/orders/` matches route `/orders/` first and falls back to `/orders`
                                                                                                                                                                                                                                                                                                                                                    *
                                                                                                                                                                                                                                                                                                                                                    * See `strict routing` at http://expressjs.com/en/4x/api.html#app
                                                                                                                                                                                                                                                                                                                                                    */
                                                                                                                                                                                                                                                                                                                                                    strict?: boolean;
                                                                                                                                                                                                                                                                                                                                                    };

                                                                                                                                                                                                                                                                                                                                                      type RestServerConfig

                                                                                                                                                                                                                                                                                                                                                      type RestServerConfig = RestServerOptions & HttpServerOptions;
                                                                                                                                                                                                                                                                                                                                                      • Valid configuration for the RestServer constructor.

                                                                                                                                                                                                                                                                                                                                                      type RestServerOptions

                                                                                                                                                                                                                                                                                                                                                      type RestServerOptions = Partial<RestServerResolvedOptions>;
                                                                                                                                                                                                                                                                                                                                                      • RestServer options

                                                                                                                                                                                                                                                                                                                                                      type RestServerResolvedConfig

                                                                                                                                                                                                                                                                                                                                                      type RestServerResolvedConfig = RestServerResolvedOptions & HttpServerOptions;

                                                                                                                                                                                                                                                                                                                                                        type RouterSpec

                                                                                                                                                                                                                                                                                                                                                        type RouterSpec = Pick<OpenApiSpec, 'paths' | 'components' | 'tags'>;

                                                                                                                                                                                                                                                                                                                                                          type SchemaValidatorCache

                                                                                                                                                                                                                                                                                                                                                          type SchemaValidatorCache = WeakMap<
                                                                                                                                                                                                                                                                                                                                                          SchemaObject | ReferenceObject, // First keyed by schema object
                                                                                                                                                                                                                                                                                                                                                          Map<string, ValidateFunction>
                                                                                                                                                                                                                                                                                                                                                          >;
                                                                                                                                                                                                                                                                                                                                                          • Cache for AJV schema validators

                                                                                                                                                                                                                                                                                                                                                          type Send

                                                                                                                                                                                                                                                                                                                                                          type Send = (response: Response, result: OperationRetval) => void;
                                                                                                                                                                                                                                                                                                                                                          • Send the operation response back to the client.

                                                                                                                                                                                                                                                                                                                                                            Parameter response

                                                                                                                                                                                                                                                                                                                                                            The response the response to send to.

                                                                                                                                                                                                                                                                                                                                                            Parameter result

                                                                                                                                                                                                                                                                                                                                                            The operation result to send.

                                                                                                                                                                                                                                                                                                                                                          type SequenceFunction

                                                                                                                                                                                                                                                                                                                                                          type SequenceFunction = (
                                                                                                                                                                                                                                                                                                                                                          context: RequestContext,
                                                                                                                                                                                                                                                                                                                                                          sequence: DefaultSequence
                                                                                                                                                                                                                                                                                                                                                          ) => ValueOrPromise<void>;
                                                                                                                                                                                                                                                                                                                                                          • A sequence function is a function implementing a custom sequence of actions to handle an incoming request.

                                                                                                                                                                                                                                                                                                                                                          Namespaces

                                                                                                                                                                                                                                                                                                                                                          namespace builtinParsers

                                                                                                                                                                                                                                                                                                                                                          namespace builtinParsers {}

                                                                                                                                                                                                                                                                                                                                                            variable json

                                                                                                                                                                                                                                                                                                                                                            const json: Symbol;

                                                                                                                                                                                                                                                                                                                                                              variable mapping

                                                                                                                                                                                                                                                                                                                                                              const mapping: { [name: string]: symbol };

                                                                                                                                                                                                                                                                                                                                                                variable names

                                                                                                                                                                                                                                                                                                                                                                const names: (string | symbol)[];

                                                                                                                                                                                                                                                                                                                                                                  variable raw

                                                                                                                                                                                                                                                                                                                                                                  const raw: Symbol;

                                                                                                                                                                                                                                                                                                                                                                    variable stream

                                                                                                                                                                                                                                                                                                                                                                    const stream: Symbol;

                                                                                                                                                                                                                                                                                                                                                                      variable text

                                                                                                                                                                                                                                                                                                                                                                      const text: Symbol;

                                                                                                                                                                                                                                                                                                                                                                        variable urlencoded

                                                                                                                                                                                                                                                                                                                                                                        const urlencoded: Symbol;

                                                                                                                                                                                                                                                                                                                                                                          namespace RestBindings

                                                                                                                                                                                                                                                                                                                                                                          namespace RestBindings {}
                                                                                                                                                                                                                                                                                                                                                                          • RestServer-specific bindings

                                                                                                                                                                                                                                                                                                                                                                          variable AJV_FACTORY

                                                                                                                                                                                                                                                                                                                                                                          const AJV_FACTORY: BindingKey<AjvFactory>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for AJV

                                                                                                                                                                                                                                                                                                                                                                          variable API_SPEC

                                                                                                                                                                                                                                                                                                                                                                          const API_SPEC: BindingKey<OpenApiSpec>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for setting and injecting an OpenAPI spec

                                                                                                                                                                                                                                                                                                                                                                          variable BASE_PATH

                                                                                                                                                                                                                                                                                                                                                                          const BASE_PATH: BindingKey<string>;
                                                                                                                                                                                                                                                                                                                                                                          • Internal binding key for basePath

                                                                                                                                                                                                                                                                                                                                                                          variable CONFIG

                                                                                                                                                                                                                                                                                                                                                                          const CONFIG: BindingKey<any>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for setting and injecting RestComponentConfig

                                                                                                                                                                                                                                                                                                                                                                          variable ERROR_WRITER_OPTIONS

                                                                                                                                                                                                                                                                                                                                                                          const ERROR_WRITER_OPTIONS: BindingKey<ErrorWriterOptions>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for setting and injecting Reject action's error handling options.

                                                                                                                                                                                                                                                                                                                                                                            See https://github.com/loopbackio/strong-error-handler#options for the list of available options. Please note that the flag log is not used by @loopback/rest.

                                                                                                                                                                                                                                                                                                                                                                          variable HANDLER

                                                                                                                                                                                                                                                                                                                                                                          const HANDLER: BindingKey<HttpHandler>;
                                                                                                                                                                                                                                                                                                                                                                          • Internal binding key for http-handler

                                                                                                                                                                                                                                                                                                                                                                          variable HOST

                                                                                                                                                                                                                                                                                                                                                                          const HOST: BindingKey<string>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for setting and injecting the host name of RestServer

                                                                                                                                                                                                                                                                                                                                                                          variable HTTPS_OPTIONS

                                                                                                                                                                                                                                                                                                                                                                          const HTTPS_OPTIONS: BindingKey<https.ServerOptions<any, any>>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for HTTPS options

                                                                                                                                                                                                                                                                                                                                                                          variable INVOKE_MIDDLEWARE_SERVICE

                                                                                                                                                                                                                                                                                                                                                                          const INVOKE_MIDDLEWARE_SERVICE: BindingKey<InvokeMiddleware>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for setting and injecting a invokeMiddleware function for middleware based sequence

                                                                                                                                                                                                                                                                                                                                                                          variable OPERATION_SPEC_CURRENT

                                                                                                                                                                                                                                                                                                                                                                          const OPERATION_SPEC_CURRENT: BindingKey<OperationObject>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for setting and injecting an OpenAPI operation spec

                                                                                                                                                                                                                                                                                                                                                                          variable PATH

                                                                                                                                                                                                                                                                                                                                                                          const PATH: BindingKey<string>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for setting and injecting the socket path of the RestServer

                                                                                                                                                                                                                                                                                                                                                                          variable PORT

                                                                                                                                                                                                                                                                                                                                                                          const PORT: BindingKey<number>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for setting and injecting the port number of RestServer

                                                                                                                                                                                                                                                                                                                                                                          variable PROTOCOL

                                                                                                                                                                                                                                                                                                                                                                          const PROTOCOL: BindingKey<HttpProtocol>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for setting and injecting the protocol of RestServer

                                                                                                                                                                                                                                                                                                                                                                          variable REQUEST_BODY_PARSER

                                                                                                                                                                                                                                                                                                                                                                          const REQUEST_BODY_PARSER: BindingKey<RequestBodyParser>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for request body parser

                                                                                                                                                                                                                                                                                                                                                                          variable REQUEST_BODY_PARSER_JSON

                                                                                                                                                                                                                                                                                                                                                                          const REQUEST_BODY_PARSER_JSON: BindingKey<BodyParser>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for request json body parser

                                                                                                                                                                                                                                                                                                                                                                          variable REQUEST_BODY_PARSER_OPTIONS

                                                                                                                                                                                                                                                                                                                                                                          const REQUEST_BODY_PARSER_OPTIONS: BindingKey<RequestBodyParserOptions>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for request body parser options

                                                                                                                                                                                                                                                                                                                                                                          variable REQUEST_BODY_PARSER_RAW

                                                                                                                                                                                                                                                                                                                                                                          const REQUEST_BODY_PARSER_RAW: BindingKey<BodyParser>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for request raw body parser

                                                                                                                                                                                                                                                                                                                                                                          variable REQUEST_BODY_PARSER_STREAM

                                                                                                                                                                                                                                                                                                                                                                          const REQUEST_BODY_PARSER_STREAM: BindingKey<BodyParser>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for request raw body parser

                                                                                                                                                                                                                                                                                                                                                                          variable REQUEST_BODY_PARSER_TEXT

                                                                                                                                                                                                                                                                                                                                                                          const REQUEST_BODY_PARSER_TEXT: BindingKey<BodyParser>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for request text body parser

                                                                                                                                                                                                                                                                                                                                                                          variable REQUEST_BODY_PARSER_URLENCODED

                                                                                                                                                                                                                                                                                                                                                                          const REQUEST_BODY_PARSER_URLENCODED: BindingKey<BodyParser>;
                                                                                                                                                                                                                                                                                                                                                                          • Binding key for request urlencoded body parser

                                                                                                                                                                                                                                                                                                                                                                          variable ROUTER

                                                                                                                                                                                                                                                                                                                                                                          const ROUTER: BindingKey<RestRouter>;
                                                                                                                                                                                                                                                                                                                                                                          • Internal binding key for rest router

                                                                                                                                                                                                                                                                                                                                                                          variable ROUTER_OPTIONS

                                                                                                                                                                                                                                                                                                                                                                          const ROUTER_OPTIONS: BindingKey<RestRouterOptions>;

                                                                                                                                                                                                                                                                                                                                                                            variable ROUTES

                                                                                                                                                                                                                                                                                                                                                                            const ROUTES: string;
                                                                                                                                                                                                                                                                                                                                                                            • Namespace for REST routes

                                                                                                                                                                                                                                                                                                                                                                            variable SEQUENCE

                                                                                                                                                                                                                                                                                                                                                                            const SEQUENCE: BindingKey<SequenceHandler>;
                                                                                                                                                                                                                                                                                                                                                                            • Binding key for setting and injecting a Sequence

                                                                                                                                                                                                                                                                                                                                                                            variable SERVER

                                                                                                                                                                                                                                                                                                                                                                            const SERVER: BindingKey<RestServer>;
                                                                                                                                                                                                                                                                                                                                                                            • Binding key for the server itself

                                                                                                                                                                                                                                                                                                                                                                            variable URL

                                                                                                                                                                                                                                                                                                                                                                            const URL: BindingKey<string>;
                                                                                                                                                                                                                                                                                                                                                                            • Binding key for setting and injecting the URL of RestServer

                                                                                                                                                                                                                                                                                                                                                                            namespace RestBindings.Http

                                                                                                                                                                                                                                                                                                                                                                            namespace RestBindings.Http {}
                                                                                                                                                                                                                                                                                                                                                                            • Request-specific bindings

                                                                                                                                                                                                                                                                                                                                                                            variable CONTEXT

                                                                                                                                                                                                                                                                                                                                                                            const CONTEXT: BindingKey<Context>;
                                                                                                                                                                                                                                                                                                                                                                            • Binding key for setting and injecting the http request context

                                                                                                                                                                                                                                                                                                                                                                            variable REQUEST

                                                                                                                                                                                                                                                                                                                                                                            const REQUEST: BindingKey<Request>;
                                                                                                                                                                                                                                                                                                                                                                            • Binding key for setting and injecting the http request

                                                                                                                                                                                                                                                                                                                                                                            variable RESPONSE

                                                                                                                                                                                                                                                                                                                                                                            const RESPONSE: BindingKey<Response<any, Record<string, any>>>;
                                                                                                                                                                                                                                                                                                                                                                            • Binding key for setting and injecting the http response

                                                                                                                                                                                                                                                                                                                                                                            namespace RestBindings.Operation

                                                                                                                                                                                                                                                                                                                                                                            namespace RestBindings.Operation {}

                                                                                                                                                                                                                                                                                                                                                                              variable PARAMS

                                                                                                                                                                                                                                                                                                                                                                              const PARAMS: BindingKey<OperationArgs>;

                                                                                                                                                                                                                                                                                                                                                                                variable RETURN_VALUE

                                                                                                                                                                                                                                                                                                                                                                                const RETURN_VALUE: BindingKey<any>;

                                                                                                                                                                                                                                                                                                                                                                                  variable ROUTE

                                                                                                                                                                                                                                                                                                                                                                                  const ROUTE: BindingKey<ResolvedRoute>;

                                                                                                                                                                                                                                                                                                                                                                                    namespace RestBindings.SequenceActions

                                                                                                                                                                                                                                                                                                                                                                                    namespace RestBindings.SequenceActions {}
                                                                                                                                                                                                                                                                                                                                                                                    • Bindings for potential actions that could be used in a sequence

                                                                                                                                                                                                                                                                                                                                                                                    variable FIND_ROUTE

                                                                                                                                                                                                                                                                                                                                                                                    const FIND_ROUTE: BindingKey<FindRoute>;
                                                                                                                                                                                                                                                                                                                                                                                    • Binding key for setting and injecting a route finding function

                                                                                                                                                                                                                                                                                                                                                                                    variable INVOKE_METHOD

                                                                                                                                                                                                                                                                                                                                                                                    const INVOKE_METHOD: BindingKey<InvokeMethod>;
                                                                                                                                                                                                                                                                                                                                                                                    • Binding key for setting and injecting a controller route invoking function

                                                                                                                                                                                                                                                                                                                                                                                    variable INVOKE_MIDDLEWARE

                                                                                                                                                                                                                                                                                                                                                                                    const INVOKE_MIDDLEWARE: BindingKey<InvokeMiddleware>;
                                                                                                                                                                                                                                                                                                                                                                                    • Binding key for setting and injecting invokeMiddleware function

                                                                                                                                                                                                                                                                                                                                                                                    variable LOG_ERROR

                                                                                                                                                                                                                                                                                                                                                                                    const LOG_ERROR: BindingKey<LogError>;
                                                                                                                                                                                                                                                                                                                                                                                    • Binding key for setting and injecting an error logging function

                                                                                                                                                                                                                                                                                                                                                                                    variable PARSE_PARAMS

                                                                                                                                                                                                                                                                                                                                                                                    const PARSE_PARAMS: BindingKey<ParseParams>;
                                                                                                                                                                                                                                                                                                                                                                                    • Binding key for setting and injecting a parameter parsing function

                                                                                                                                                                                                                                                                                                                                                                                    variable REJECT

                                                                                                                                                                                                                                                                                                                                                                                    const REJECT: BindingKey<Reject>;
                                                                                                                                                                                                                                                                                                                                                                                    • Binding key for setting and injecting a bad response writing function

                                                                                                                                                                                                                                                                                                                                                                                    variable SEND

                                                                                                                                                                                                                                                                                                                                                                                    const SEND: BindingKey<Send>;
                                                                                                                                                                                                                                                                                                                                                                                    • Binding key for setting and injecting a response writing function

                                                                                                                                                                                                                                                                                                                                                                                    namespace RestHttpErrors

                                                                                                                                                                                                                                                                                                                                                                                    namespace RestHttpErrors {}

                                                                                                                                                                                                                                                                                                                                                                                      variable INVALID_REQUEST_BODY_MESSAGE

                                                                                                                                                                                                                                                                                                                                                                                      const INVALID_REQUEST_BODY_MESSAGE: string;

                                                                                                                                                                                                                                                                                                                                                                                        function invalidData

                                                                                                                                                                                                                                                                                                                                                                                        invalidData: <T, Props extends object = {}>(
                                                                                                                                                                                                                                                                                                                                                                                        data: T,
                                                                                                                                                                                                                                                                                                                                                                                        name: string,
                                                                                                                                                                                                                                                                                                                                                                                        extraProperties?: Props
                                                                                                                                                                                                                                                                                                                                                                                        ) => HttpErrors.HttpError & Props;

                                                                                                                                                                                                                                                                                                                                                                                          function invalidParamLocation

                                                                                                                                                                                                                                                                                                                                                                                          invalidParamLocation: (location: string) => HttpErrors.HttpError;

                                                                                                                                                                                                                                                                                                                                                                                            function invalidRequestBody

                                                                                                                                                                                                                                                                                                                                                                                            invalidRequestBody: (
                                                                                                                                                                                                                                                                                                                                                                                            details: ValidationErrorDetails[]
                                                                                                                                                                                                                                                                                                                                                                                            ) => HttpErrors.HttpError & { details: ValidationErrorDetails[] };

                                                                                                                                                                                                                                                                                                                                                                                              function missingRequired

                                                                                                                                                                                                                                                                                                                                                                                              missingRequired: (name: string) => HttpErrors.HttpError;

                                                                                                                                                                                                                                                                                                                                                                                                function unsupportedMediaType

                                                                                                                                                                                                                                                                                                                                                                                                unsupportedMediaType: (
                                                                                                                                                                                                                                                                                                                                                                                                contentType: string,
                                                                                                                                                                                                                                                                                                                                                                                                allowedTypes?: string[]
                                                                                                                                                                                                                                                                                                                                                                                                ) => HttpErrors.HttpError<415> & {
                                                                                                                                                                                                                                                                                                                                                                                                code: string;
                                                                                                                                                                                                                                                                                                                                                                                                contentType: string;
                                                                                                                                                                                                                                                                                                                                                                                                allowedMediaTypes: string[];
                                                                                                                                                                                                                                                                                                                                                                                                };

                                                                                                                                                                                                                                                                                                                                                                                                  interface ValidationErrorDetails

                                                                                                                                                                                                                                                                                                                                                                                                  interface ValidationErrorDetails {}
                                                                                                                                                                                                                                                                                                                                                                                                  • An invalid request body error contains a details property as the machine-readable error. Each entry in error.details contains 4 attributes: path, code, info and message. ValidationErrorDetails defines the type of each entry, which is an object. The type of error.details is ValidationErrorDetails[].

                                                                                                                                                                                                                                                                                                                                                                                                  property code

                                                                                                                                                                                                                                                                                                                                                                                                  code: string;
                                                                                                                                                                                                                                                                                                                                                                                                  • A single word code represents the error's type.

                                                                                                                                                                                                                                                                                                                                                                                                  property info

                                                                                                                                                                                                                                                                                                                                                                                                  info: object;
                                                                                                                                                                                                                                                                                                                                                                                                  • Some additional details that the 3 attributes above don't cover.

                                                                                                                                                                                                                                                                                                                                                                                                  property message

                                                                                                                                                                                                                                                                                                                                                                                                  message: string;
                                                                                                                                                                                                                                                                                                                                                                                                  • A human readable description of the error.

                                                                                                                                                                                                                                                                                                                                                                                                  property path

                                                                                                                                                                                                                                                                                                                                                                                                  path: string;
                                                                                                                                                                                                                                                                                                                                                                                                  • A path to the invalid field.

                                                                                                                                                                                                                                                                                                                                                                                                  namespace RestMiddlewareGroups

                                                                                                                                                                                                                                                                                                                                                                                                  namespace RestMiddlewareGroups {}
                                                                                                                                                                                                                                                                                                                                                                                                  • Built-in middleware groups for the REST sequence

                                                                                                                                                                                                                                                                                                                                                                                                  variable API_SPEC

                                                                                                                                                                                                                                                                                                                                                                                                  const API_SPEC: string;
                                                                                                                                                                                                                                                                                                                                                                                                  • Server OpenAPI specs

                                                                                                                                                                                                                                                                                                                                                                                                  variable AUTHENTICATION

                                                                                                                                                                                                                                                                                                                                                                                                  const AUTHENTICATION: string;
                                                                                                                                                                                                                                                                                                                                                                                                  • Perform authentication

                                                                                                                                                                                                                                                                                                                                                                                                  variable CORS

                                                                                                                                                                                                                                                                                                                                                                                                  const CORS: string;
                                                                                                                                                                                                                                                                                                                                                                                                  • Enforce CORS

                                                                                                                                                                                                                                                                                                                                                                                                  variable DEFAULT

                                                                                                                                                                                                                                                                                                                                                                                                  const DEFAULT: string;

                                                                                                                                                                                                                                                                                                                                                                                                    variable FIND_ROUTE

                                                                                                                                                                                                                                                                                                                                                                                                    const FIND_ROUTE: string;
                                                                                                                                                                                                                                                                                                                                                                                                    • Find the route that can serve the request

                                                                                                                                                                                                                                                                                                                                                                                                    variable INVOKE_METHOD

                                                                                                                                                                                                                                                                                                                                                                                                    const INVOKE_METHOD: string;
                                                                                                                                                                                                                                                                                                                                                                                                    • Invoke the target controller method or handler function

                                                                                                                                                                                                                                                                                                                                                                                                    variable MIDDLEWARE

                                                                                                                                                                                                                                                                                                                                                                                                    const MIDDLEWARE: string;
                                                                                                                                                                                                                                                                                                                                                                                                    • Default middleware group

                                                                                                                                                                                                                                                                                                                                                                                                    variable PARSE_PARAMS

                                                                                                                                                                                                                                                                                                                                                                                                    const PARSE_PARAMS: string;
                                                                                                                                                                                                                                                                                                                                                                                                    • Parse the http request to extract parameter values for the operation

                                                                                                                                                                                                                                                                                                                                                                                                    variable SEND_RESPONSE

                                                                                                                                                                                                                                                                                                                                                                                                    const SEND_RESPONSE: string;
                                                                                                                                                                                                                                                                                                                                                                                                    • Invoke downstream middleware to get the result or catch errors so that it can produce the http response

                                                                                                                                                                                                                                                                                                                                                                                                    namespace RestTags

                                                                                                                                                                                                                                                                                                                                                                                                    namespace RestTags {}
                                                                                                                                                                                                                                                                                                                                                                                                    • Binding tags for RestServer

                                                                                                                                                                                                                                                                                                                                                                                                    variable ACTION_MIDDLEWARE_CHAIN

                                                                                                                                                                                                                                                                                                                                                                                                    const ACTION_MIDDLEWARE_CHAIN: string;
                                                                                                                                                                                                                                                                                                                                                                                                    • Legacy middleware chain for action-based REST sequence

                                                                                                                                                                                                                                                                                                                                                                                                    variable AJV_FORMAT

                                                                                                                                                                                                                                                                                                                                                                                                    const AJV_FORMAT: string;

                                                                                                                                                                                                                                                                                                                                                                                                      variable AJV_KEYWORD

                                                                                                                                                                                                                                                                                                                                                                                                      const AJV_KEYWORD: string;

                                                                                                                                                                                                                                                                                                                                                                                                        variable CONTROLLER_BINDING

                                                                                                                                                                                                                                                                                                                                                                                                        const CONTROLLER_BINDING: string;
                                                                                                                                                                                                                                                                                                                                                                                                        • Binding tag for controller route bindings to represent the controller binding key

                                                                                                                                                                                                                                                                                                                                                                                                        variable CONTROLLER_ROUTE

                                                                                                                                                                                                                                                                                                                                                                                                        const CONTROLLER_ROUTE: string;
                                                                                                                                                                                                                                                                                                                                                                                                        • Binding tag to identify controller based REST routes

                                                                                                                                                                                                                                                                                                                                                                                                        variable REST_MIDDLEWARE_CHAIN

                                                                                                                                                                                                                                                                                                                                                                                                        const REST_MIDDLEWARE_CHAIN: string;

                                                                                                                                                                                                                                                                                                                                                                                                          variable REST_ROUTE

                                                                                                                                                                                                                                                                                                                                                                                                          const REST_ROUTE: string;
                                                                                                                                                                                                                                                                                                                                                                                                          • Binding tag to identify REST routes

                                                                                                                                                                                                                                                                                                                                                                                                          variable ROUTE_PATH

                                                                                                                                                                                                                                                                                                                                                                                                          const ROUTE_PATH: string;
                                                                                                                                                                                                                                                                                                                                                                                                          • Binding tag for the REST route path

                                                                                                                                                                                                                                                                                                                                                                                                          variable ROUTE_VERB

                                                                                                                                                                                                                                                                                                                                                                                                          const ROUTE_VERB: string;
                                                                                                                                                                                                                                                                                                                                                                                                          • Binding tag for the REST route verb

                                                                                                                                                                                                                                                                                                                                                                                                          Package Files (43)

                                                                                                                                                                                                                                                                                                                                                                                                          Dependencies (31)

                                                                                                                                                                                                                                                                                                                                                                                                          Dev Dependencies (15)

                                                                                                                                                                                                                                                                                                                                                                                                          Peer Dependencies (1)

                                                                                                                                                                                                                                                                                                                                                                                                          Badge

                                                                                                                                                                                                                                                                                                                                                                                                          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                                                                                                                                                                                                                                                          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@loopback/rest.

                                                                                                                                                                                                                                                                                                                                                                                                          • Markdown
                                                                                                                                                                                                                                                                                                                                                                                                            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@loopback/rest)
                                                                                                                                                                                                                                                                                                                                                                                                          • HTML
                                                                                                                                                                                                                                                                                                                                                                                                            <a href="https://www.jsdocs.io/package/@loopback/rest"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>