Syntax

response(
  statusCode: $statusCode, 
  content: $content, 
  contentType: $contentType
)

Description

Creates a response object that is returned in response to an HTTP request.

If the operation is executed within a transaction, the statusCode determines its outcome: a successful status (2xx) commits the transaction, any other status rolls it back. This ensures that no changes are persisted to the database when the response indicates a failure.

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
Object
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
Content type of the response. This must match the result of the response.
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.