Constructor
new ResponseSystemMiddleware(app, response, request)
Instantiate the middleware. Bootstrap the response with methods.
Name | Type | Description |
---|---|---|
app |
module:libflitter/app/FlitterApp~FlitterApp | the Flitter app |
response |
express/response | the Express response |
request |
express/request | the Express request |
Extends
Members
(static) services
Defines the services required by this unit.
(private) _di_allow_defer :boolean
If true, the injector will defer the class if the class requests any services that the container is missing. These services are filled in later and added to the prototype and any instances. True by default.
- boolean
- Source:
(private) _di_deferred_instances :Array.<module:flitter-di/src/Injectable~Injectable>
Collection of instances of this class that need to have the deferred service instances injected into them when the deferred services are finally provided.
- Source:
(private) _di_deferred_services :Array.<string>
List of services that were deferred and not provided at the time of injection.
- Array.<string>
- Source:
Methods
(async) api(data) → {Promise.<*>}
Sends an JSON-formatted response in a standard API format containing the HTTP status code, some message, and a data key with the passed in data.
Name | Type | Description |
---|---|---|
data |
- Type
- Promise.<*>
(async) error(status, params) → {Promise.<*>}
Sends an HTTP error and renders the error view with the corresponding status code. If the status code cannot be resolved to an integer, the request status will default to 400. Wraps the {module:libflitter/views/ViewEngineUnit~ViewEngineUnit#error} method.
Name | Type | Description |
---|---|---|
status |
string | int | HTTP or error status code |
params |
Object | collection of arguments to be passed to the view. The "code" key will be overwritten with the status. |
- Type
- Promise.<*>
message(msg) → {express|response}
Sets the response message, if used.
Name | Type | Default | Description |
---|---|---|---|
msg |
OK |
- Type
- express | response
(async) page(view_name, args, resource_list) → {Promise.<*>}
Renders a view for the user. Wraps the {module:libflitter/views/ViewEngineUnit~ViewEngineUnit#view} method. Additionally, adds the _app variable to the view, which contains page-specific information like the title. See {module:libflitter/routing/ResponseSystemMiddleware~ResponseSystemMiddleware~PageAppData} for more info.
Name | Type | Description |
---|---|---|
view_name |
string | the Flitter canonical name of the view to be rendered |
args |
Object | variables to be passed to the view |
resource_list |
Array.<module:libflitter/views/ViewEngineUnit~ViewEngineUnit~ResourceSpec> | an array of resource specifications to be passed to the view |
- returns the output of the wrapped function
- Type
- Promise.<*>
status(code) → {express|response}
Sets the response status code.
Name | Type | Default | Description |
---|---|---|---|
code |
200 |
- Type
- express | response
(async) view(view_name, args, resource_list) → {Promise.<*>}
Renders a view for the user. Wraps the {module:libflitter/views/ViewEngineUnit~ViewEngineUnit#view} method.
Name | Type | Description |
---|---|---|
view_name |
string | the Flitter canonical name of the view to be rendered |
args |
Object | variables to be passed to the view |
resource_list |
Array.<module:libflitter/views/ViewEngineUnit~ViewEngineUnit~ResourceSpec> | an array of resource specifications to be passed to the view |
- returns the output of the wrapped function
- Type
- Promise.<*>