@absolunet/ioc2.1.0

View on GitHub

Controller

Abstract controller class that defines all the shortcuts to take action on the response object.

Members

writeStreamLineHandler :function

Source:
Command streaming interceptor handler.

isStreaming :boolean

Source:
Indicates if the response is currently streaming.

request :request

Source:
Express request.

response :response

Source:
Express response.

Methods

prepareHandling(app, request, response)

Source:
Prepare request handling.
Parameters:
Name Type Description
app container.Container The current container instance.
request request The current request instance.
response response The current response instance.

view(view, data)

Source:
Send HTML response.
Parameters:
Name Type Description
view string The view name.
data * The view-model data.
Returns:
The response instance.
Type
response

json(object)

Source:
Send JSON response.
Parameters:
Name Type Description
object string | number | boolean | object The JSON value to send.
Returns:
The response instance.
Type
response

dump(…parameters)

Source:
Dump parameters in the current response.
Parameters:
Name Type Attributes Description
parameters * <repeatable>
The dumped values.

(async) stream(handler)

Source:
Send a stream response. Ends the request when the handler resolves.
Parameters:
Name Type Description
handler function The stream handler.
Returns:
The async process promise.
Type
Promise

writeStreamLine(line)

Source:
Write line in the stream response.
Parameters:
Name Type Description
line string The line to stream into the response.
Returns:
The current controller instance.
Type
http.controllers.Controller

streamCommand(command)

Source:
Send a stream response from command output.
Parameters:
Name Type Description
command string | Array.<string> The command string.
Returns:
The async process promise.
Type
Promise

(async) runCommand(command, handleropt)

Source:
Run command. Handle output if an handler is provided.
Parameters:
Name Type Attributes Default Description
command string | Array.<string> The command string.
handler function | null <optional>
null The handler that will received printed data after command will have run.
Returns:
The async process promise.
Type
Promise

validate(validationClosure)

Source:
Validate the current request body against the given schema.
Parameters:
Name Type Description
validationClosure function The validation callback that returns the validation schema.

redirect(to, permanentopt)

Source:
Redirect to the given URL with the appropriate redirection code.
Parameters:
Name Type Attributes Default Description
to string The URL to redirect to.
permanent boolean <optional>
false Indicates that the redirection response should flag a permanent redirection.
Returns:
The current response instance.
Type
response

permanentRedirect(to)

Source:
Redirect to the given URL permanently.
Parameters:
Name Type Description
to string The URL to redirect to.
Returns:
The current response instance.
Type
response

status(status)

Source:
Set response status.
Parameters:
Name Type Description
status number The HTTP status code.
Returns:
The current controller instance.
Type
http.controllers.Controller

throwWithStatus(status)

Source:
Set response status and throw an HTTP error that reflects the given status.
Parameters:
Name Type Description
status number The HTTP status code.
Throws:
The corresponding HTTP error based on the HTTP status code.
Type
http.exceptions.HttpError

ok()

Source:
Set 200 OK status.
Returns:
The current controller instance.
Type
http.controllers.Controller

created()

Source:
Set 201 Created status.
Returns:
The current controller instance.
Type
http.controllers.Controller

accepted()

Source:
Set 202 Accepted status.
Returns:
The current controller instance.
Type
http.controllers.Controller

noContent()

Source:
Set 204 No Content status.
Returns:
The current controller instance.
Type
http.controllers.Controller

badRequest()

Source:
Set 400 Bad Request status.
Returns:
The current controller instance.
Type
http.controllers.Controller

unauthorized()

Source:
Set 401 Unauthorized status.
Returns:
The current controller instance.
Type
http.controllers.Controller

forbidden()

Source:
Set 403 Forbidden status.
Returns:
The current controller instance.
Type
http.controllers.Controller

notFound()

Source:
Set 404 Not Found status.
Returns:
The current controller instance.
Type
http.controllers.Controller

methodNotAllowed()

Source:
Set 405 Method Not Allowed status.
Returns:
The current controller instance.
Type
http.controllers.Controller

timeout()

Source:
Set 408 Timeout status.
Returns:
The current controller instance.
Type
http.controllers.Controller

teapot()

Source:
Set 418 I'm A Teapot status.
Returns:
The current controller instance.
Type
http.controllers.Controller