Requires Scripting PRO
The HttpResponse class represents an HTTP response object returned by the server to the client.
It defines the response’s status code, headers, and body, and provides convenient factory methods for creating common HTTP responses (e.g., ok, notFound, internalServerError).
HttpResponse is typically used together with HttpResponseBody to send text, HTML, binary data, or files back to the client.
HttpResponse provides:
FileEntity and Data for flexible body contentstatusCode: numberThe numeric HTTP status code.
Example:
reasonPhrase: stringThe reason phrase associated with the status code (e.g., "OK", "Not Found", "Internal Server Error").
Example:
headers(): Record<string, string>Returns the headers of the response as a key–value object.
Example:
static ok(body: HttpResponseBody): HttpResponseCreates a 200 OK response.
Parameters:
| Name | Type | Description |
|---|---|---|
body |
HttpResponseBody |
The response body (use HttpResponseBody.text(), data(), or html()). |
Example:
static created(): HttpResponseReturns a 201 Created response, indicating that a new resource was successfully created.
Example:
static accepted(): HttpResponseReturns a 202 Accepted response, indicating the request was accepted but not yet processed.
Example:
static movedPermanently(url: string): HttpResponseReturns a 301 Moved Permanently redirect response.
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string |
The target URL to redirect to. |
Example:
static movedTemporarily(url: string): HttpResponseReturns a 302 Moved Temporarily redirect response.
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string |
The temporary redirect target URL. |
Example:
static badRequest(body?: HttpResponseBody | null): HttpResponseReturns a 400 Bad Request response, indicating invalid parameters or malformed input.
Parameters:
| Name | Type | Description |
|---|---|---|
body |
HttpResponseBody? |
Optional error body describing the issue. |
Example:
static unauthorized(): HttpResponseReturns a 401 Unauthorized response, indicating authentication is required.
Example:
static forbidden(): HttpResponseReturns a 403 Forbidden response, indicating the request is understood but not allowed.
Example:
static notFound(): HttpResponseReturns a 404 Not Found response when the requested resource does not exist.
Example:
static notAcceptable(): HttpResponseReturns a 406 Not Acceptable response, indicating the request’s content type is unsupported.
Example:
static tooManyRequests(): HttpResponseReturns a 429 Too Many Requests response, indicating the client is sending requests too quickly.
Example:
static internalServerError(): HttpResponseReturns a 500 Internal Server Error response, indicating an unexpected server error occurred.
Example:
static raw(statusCode: number, phrase: string, options?: { headers?: Record<string, string>; body?: Data | FileEntity } | null): HttpResponseCreates a fully custom response with a specific status code, reason phrase, headers, and body.
Parameters:
| Name | Type | Description |
|---|---|---|
statusCode |
number |
The HTTP status code. |
phrase |
string |
The reason phrase. |
options.headers |
Record<string, string> |
Optional custom headers. |
options.body |
Data | FileEntity |
Optional response body (binary data or file). |
Example:
HttpResponseBody.text(text: string)Returns a plain-text response body.
HttpResponseBody.html(html: string)Returns an HTML response body.
HttpResponseBody.data(data: Data)Returns a binary data response body.