| Name | Type | Description |
|---|---|---|
| handleRequest |
Function
|
| Name | Type | Description |
|---|---|---|
| _rootContext |
Context
|
| Name | Type | Description |
|---|---|---|
| request |
ParsedRequest
|
| Name | Type | Description |
|---|---|---|
| defs |
SchemasObject
|
| Name | Type | Description |
|---|---|---|
| spec |
ControllerSpec
|
|
| controllerCtor |
ControllerClass
|
|
| controllerFactory |
ControllerFactory
|
| Name | Type | Description |
|---|---|---|
| route |
RouteEntry
|
| Name | Type | Description |
|---|---|---|
| method |
string
|
|
| path |
string
|
|
| pathname |
string
|
|
| query |
Function
|
|
| url |
string
|
| Name | Type | Description |
|---|---|---|
| key |
string
|
Find a route matching the incoming request. Throw an error when no route was found.
| Name | Type | Description |
|---|---|---|
| request |
ParsedRequest
|
| Name | Type | Description |
|---|---|---|
| key |
string
|
Invokes a method defined in the Application Controller
Returns:OperationRetval Result from method invocation
| Name | Type | Description |
|---|---|---|
| route |
RouteEntry
|
|
| args |
OperationArgs
|
Operation arguments for the method |
Log information about a failed request.
Returns:| Name | Type | Description |
|---|---|---|
| err |
Error
|
The error reported by request handling code. |
| statusCode |
number
|
Status code of the HTTP response |
| request |
ServerRequest
|
The request that failed. |
| Name | Type | Description |
|---|---|---|
| request |
ParsedRequest
|
|
| route |
ResolvedRoute
|
| Name | Type | Description |
|---|---|---|
| key |
string
|
Reject the request with an error.
Returns:| Name | Type | Description |
|---|---|---|
| response |
ServerResponse
|
The response the response to send to. |
| request |
ServerRequest
|
The request that triggered the error. |
| err |
Error
|
The error. |
Send the operation response back to the client.
Returns:| Name | Type | Description |
|---|---|---|
| response |
ServerResponse
|
The response the response to send to. |
| result |
OperationRetval
|
The operation result to send. |
Parses the request to derive arguments to be passed in for the Application controller method
| Name | Type | Description |
|---|---|---|
| request |
ParsedRequest
|
Incoming HTTP request |
| route |
ResolvedRoute
|
| Name | Type | Description |
|---|---|---|
| context |
Context
|
| Name | Type | Description |
|---|---|---|
| key |
string
|
| Name | Type | Description |
|---|---|---|
| context |
Context
|
|
| handler |
HttpHandler
|
| Name | Type | Description |
|---|---|---|
| request |
ParsedRequest
|
| Name | Type | Description |
|---|---|---|
| context |
Context
|
| Name | Type | Description |
|---|---|---|
| key |
string
|
| Name | Type | Description |
|---|---|---|
| context |
Context
|
| Name | Type | Description |
|---|---|---|
| route |
RouteEntry
|
|
| args |
OperationArgs
|
| Name | Type | Description |
|---|---|---|
| err |
Error
|
|
| statusCode |
number
|
|
| req |
ServerRequest
|
Provides the function for parsing args in requests at runtime.
| Name | Type | Description |
|---|---|---|
| logError |
LogError
|
| Name | Type | Description |
|---|---|---|
| response |
ServerResponse
|
|
| request |
ServerRequest
|
|
| error |
Error
|
Provides the function that populates the response object with the results of the operation.
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.
| Name | Type | Description |
|---|---|---|
| config |
ApplicationConfig
|
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. |
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).
| Name | Type | Description |
|---|---|---|
| spec |
OpenApiSpec
|
The OpenAPI specification, as an object. |
| Name | Type | Description |
|---|---|---|
| handlerFn |
SequenceFunction
|
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. |
Register a new Controller-based route.
class MyController {
greet(name: string) {
return `hello ${name}`;
}
}
app.route('get', '/greet', operationSpec, MyController, 'greet');
| Name | Type | Description |
|---|---|---|
| verb |
string
|
HTTP verb of the endpoint |
| path |
string
|
URL path of the endpoint |
| spec |
OperationObject
|
The OpenAPI spec describing the endpoint (operation) |
| controllerCtor |
ControllerClass
|
Controller constructor |
| controllerFactory |
ControllerFactory
|
A factory function to create controller instance |
| methodName |
string
|
The name of the controller method |
Register a new route.
function greet(name: string) {
return `hello ${name}`;
}
const route = new Route('get', '/', operationSpec, greet);
app.route(route);
| Name | Type | Description |
|---|---|---|
| route |
RouteEntry
|
The route to add. |
| Name | Type | Description |
|---|---|---|
| sequence |
Constructor
|
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. |
| Name | Type | Description |
|---|---|---|
| server |
Constructor
|
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. |
| name |
|
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. |
| Name | Type | Description |
|---|---|---|
| app |
Application
|
|
| config |
RestComponentConfig
|
A REST API server for use with Loopback. Add this server to your application by importing the RestComponent.
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');
| Name | Type | Description |
|---|---|---|
| requestHandler |
HttpRequestListener
|
Handle incoming HTTP(S) request by invoking the corresponding Controller method via the configured Sequence. |
| Name | Type | Description |
|---|---|---|
| app |
Application
|
The application instance (injected via CoreBindings.APPLICATION_INSTANCE). |
| options |
RestServerConfig
|
The configuration options (injected via RestBindings.CONFIG). |
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).
| Name | Type | Description |
|---|---|---|
| spec |
OpenApiSpec
|
The OpenAPI specification, as an object. |
Register a controller class with this server.
The newly created binding, you can use the reference to further modify the binding, e.g. lock the value to prevent further modifications.
class MyController {
}
app.controller(MyController).lock();
| Name | Type | Description |
|---|---|---|
| controllerCtor |
ControllerClass
|
The controller class (constructor function). |
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')Configure a custom sequence function for handling incoming requests.
app.handler((sequence, request, response) => {
sequence.send(response, 'hello world');
});
| Name | Type | Description |
|---|---|---|
| handlerFn |
SequenceFunction
|
The handler to invoke for each incoming request. |
Register a new Controller-based route.
class MyController {
greet(name: string) {
return `hello ${name}`;
}
}
app.route('get', '/greet', operationSpec, MyController, 'greet');
| Name | Type | Description |
|---|---|---|
| verb |
string
|
HTTP verb of the endpoint |
| path |
string
|
URL path of the endpoint |
| spec |
OperationObject
|
The OpenAPI spec describing the endpoint (operation) |
| controllerCtor |
ControllerClass
|
Controller constructor |
| controllerFactory |
ControllerFactory
|
A factory function to create controller instance |
| methodName |
string
|
The name of the controller method |
Register a new route.
function greet(name: string) {
return `hello ${name}`;
}
const route = new Route('get', '/', operationSpec, greet);
app.route(route);
| Name | Type | Description |
|---|---|---|
| route |
RouteEntry
|
The route to add. |
Configure a custom sequence class for handling incoming requests.
class MySequence implements SequenceHandler {
constructor(
@inject('send) public send: Send)) {
}
public async handle(request: ParsedRequest, response: ServerResponse) {
send(response, 'hello world');
}
}
| Name | Type | Description |
|---|---|---|
| value |
Constructor
|
The sequence to invoke for each incoming request. |
Start this REST API's HTTP/HTTPS server.
Stop this REST API's HTTP/HTTPS server.
| Name | Type | Description |
|---|---|---|
| requestHandler |
HttpRequestListener
|
The object format used for building the template bases of our OpenAPI spec files.
Valid configuration for the RestServer constructor.
| Name | Type | Description |
|---|---|---|
| apiExplorerUrl |
|
Valid configuration for the RestServer constructor. |
| cors |
cors.CorsOptions
|
Valid configuration for the RestServer constructor. |
| host |
|
Valid configuration for the RestServer constructor. |
| port |
|
Valid configuration for the RestServer constructor. |
| sequence |
Constructor
|
Valid configuration for the RestServer constructor. |
| Name | Type | Description |
|---|---|---|
| req |
ServerRequest
|
|
| res |
ServerResponse
|
Base implementation of RouteEntry
| Name | Type | Description |
|---|---|---|
| path |
string
|
http request path pattern |
| spec |
OperationObject
|
OpenAPI operation spec |
| verb |
string
|
Base implementation of RouteEntry |
Construct a new route
| Name | Type | Description |
|---|---|---|
| verb |
string
|
http verb |
| path |
string
|
http request path pattern |
| spec |
OperationObject
|
OpenAPI operation spec |
| Name | Type | Description |
|---|---|---|
| requestContext |
Context
|
Base implementation of RouteEntry |
| args |
OperationArgs
|
Base implementation of RouteEntry |
| Name | Type | Description |
|---|---|---|
| request |
ParsedRequest
|
Base implementation of RouteEntry |
| Name | Type | Description |
|---|---|---|
| requestContext |
Context
|
Base implementation of RouteEntry |
A route backed by a controller
Construct a controller based route
| Name | Type | Description |
|---|---|---|
| verb |
string
|
http verb |
| path |
string
|
http request path |
| spec |
OperationObject
|
OpenAPI operation spec |
| controllerCtor |
ControllerClass
|
Controller class |
| controllerFactory |
ControllerFactory
|
A factory function to create a controller instance |
| methodName |
|
Controller method name, default to |
| Name | Type | Description |
|---|---|---|
| requestContext |
Context
|
A route backed by a controller |
| args |
OperationArgs
|
A route backed by a controller |
| Name | Type | Description |
|---|---|---|
| requestContext |
Context
|
A route backed by a controller |
| Name | Type | Description |
|---|---|---|
| spec |
OperationObject
|
| Name | Type | Description |
|---|---|---|
| verb |
string
|
|
| path |
string
|
|
| spec |
OperationObject
|
|
| _handler |
Function
|
| Name | Type | Description |
|---|---|---|
| requestContext |
Context
|
|
| args |
OperationArgs
|
| Name | Type | Description |
|---|---|---|
| requestContext |
Context
|
Routing table
Map a request to a route
| Name | Type | Description |
|---|---|---|
| request |
ParsedRequest
|
|
Register a controller as the route
| Name | Type | Description |
|---|---|---|
| spec |
ControllerSpec
|
|
| controllerCtor |
ControllerClass
|
|
| controllerFactory |
ControllerFactory
|
|
Register a route
| Name | Type | Description |
|---|---|---|
| route |
RouteEntry
|
A route entry |
| Name | Type | Description |
|---|---|---|
| basePath |
string
|
Routing table |
| path |
string
|
Routing table |
A route with path parameters resolved
| Name | Type | Description |
|---|---|---|
| pathParams |
PathParameterValues
|
A route with path parameters resolved |
An entry in the routing table
| Name | Type | Description |
|---|---|---|
| path |
string
|
http path |
| spec |
OperationObject
|
OpenAPI operation spec |
| verb |
string
|
http verb |
A handler to invoke the resolved controller method
| Name | Type | Description |
|---|---|---|
| requestContext |
Context
|
|
| args |
OperationArgs
|
|
Map an http request to a route
| Name | Type | Description |
|---|---|---|
| request |
ParsedRequest
|
|
Update bindings for the request context
| Name | Type | Description |
|---|---|---|
| requestContext |
Context
|
|
A factory function to create controller instances synchronously or asynchronously
| Name | Type | Description |
|---|---|---|
| ctx |
Context
|
Create a controller factory function for a given binding key
| Name | Type | Description |
|---|---|---|
| key |
string
|
Binding key |
Create a controller factory function for a given class
| Name | Type | Description |
|---|---|---|
| controllerCtor |
ControllerClass
|
Controller class |
Create a controller factory function for a given instance
| Name | Type | Description |
|---|---|---|
| controllerInst |
T
|
| Name | Type | Description |
|---|---|---|
| route |
RouteEntry
|
|
| pathParams |
PathParameterValues
|
Parse the URL of the incoming request and set additional properties on this request object:
pathquery| Name | Type | Description |
|---|---|---|
| request |
ServerRequest
|
|
The default implementation of SequenceHandler.
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.
User can bind their own Sequence to app as shown below
app.bind(CoreBindings.SEQUENCE).toClass(MySequence);
| Name | Type | Description |
|---|---|---|
| ctx |
Context
|
The context for the sequence (injected via RestBindings.Http.CONTEXT). |
| reject |
Reject
|
The action to take if the invoke returns a rejected promise result (injected via SequenceActions.REJECT). |
| send |
Send
|
The action to merge the invoke result with the response (injected via SequenceActions.SEND) |
Constructor: Injects findRoute, invokeMethod & logError methods as promises.
| Name | Type | Description |
|---|---|---|
| ctx |
Context
|
The context for the sequence (injected via RestBindings.Http.CONTEXT). |
| findRoute |
FindRoute
|
Finds the appropriate controller method, spec and args for invocation (injected via SequenceActions.FIND_ROUTE). |
| parseParams |
ParseParams
|
The parameter parsing function (injected via SequenceActions.PARSE_PARAMS). |
| invoke |
InvokeMethod
|
Invokes the method specified by the route (injected via SequenceActions.INVOKE_METHOD). |
| send |
Send
|
The action to merge the invoke result with the response (injected via SequenceActions.SEND) |
| reject |
Reject
|
The action to take if the invoke returns a rejected promise result (injected via SequenceActions.REJECT). |
Runs the default sequence. Given a request and response, running the sequence will produce a response or an error.
Default sequence executes these steps
| Name | Type | Description |
|---|---|---|
| req |
ParsedRequest
|
Parsed incoming HTTP request |
| res |
ServerResponse
|
HTTP server response with result from Application controller method invocation |
A sequence handler is a class implementing sequence of actions required to handle an incoming request.
Handle the request by running the configured sequence of actions.
| Name | Type | Description |
|---|---|---|
| request |
ParsedRequest
|
The incoming HTTP request |
| response |
ServerResponse
|
The HTTP server response where to write the result |
A sequence function is a function implementing a custom sequence of actions to handle an incoming request.
| Name | Type | Description |
|---|---|---|
| sequence |
DefaultSequence
|
|
| request |
ParsedRequest
|
|
| response |
ServerResponse
|
Write an error into the HTTP response
| Name | Type | Description |
|---|---|---|
| response |
Response
|
HTTP response |
| error |
Error
|
Error |
Writes the result from Application controller method into the HTTP response
| Name | Type | Description |
|---|---|---|
| response |
Response
|
HTTP Response |
| result |
OperationRetval
|
Result from the API to write into HTTP Response |