Response
Syntax
response(
statusCode: $statusCode,
content: $content,
contentType: $contentType
)
Description
Creates a response object that is returned in response to an HTTP request.
Parameters
name | Type | Description | Mandatory | Default | |
---|---|---|---|---|---|
statusCode | Number | Status code for the response. HTTP response codes are specified here, e.g. 200 (OK) or 404 (NOT FOUND). | yes | ||
content |
|
Content of the response. If no content is given, the status code is interpreted as an error code and the standard response of the container is sent. | no | ||
contentType | Character string |
|
no | application/json |
Examples
Example 1
response(200, {"name": "Rüdiger"});
The request was successful and {"name": "Rüdiger"}
is sent with the content type application/json
.
Example 2
response(404);
The standard response is sent that the resource was not found.
Example 3
response(
500,
"<html>
<head><title>Error 500 Server Error</title></head>
<body><h2>HTTP ERROR 500 Server Error</h2></body>
</html>",
"text/html");
The error code 500
is sent with the given content.