Requires Scripting PRO
The HttpResponseBody class represents the body content of an HTTP response.
It can contain text, HTML, binary data, or other forms of content.
HttpResponseBody is typically used with the HttpResponse class to return formatted data to the client.
When building custom HTTP endpoints with HttpServer, the response body defines what content the client actually receives.
HttpResponseBody provides convenient static factory methods to construct various types of response content:
text)html, htmlBody)data)static text(text: string): HttpResponseBodyCreates a plain-text response body.
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string |
The text content to include in the response body. |
Example:
Response example:
static data(data: Data): HttpResponseBodyCreates a response body containing binary data.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Data |
The binary data object to send in the response body. |
Example:
This is useful for sending files, images, or JSON payloads as binary data.
static html(html: string): HttpResponseBodyCreates an HTML response body (standard HTML document).
Parameters:
| Name | Type | Description |
|---|---|---|
html |
string |
The HTML markup to include in the response body. |
Example:
When accessed in a browser, the response is rendered as a web page.
static htmlBody(html: string): HttpResponseBodyCreates an HTML body-only response.
Similar to html(), but may exclude full document structure (<html>, <body>, etc.).
This method is often used for partial HTML rendering or embedded HTML fragments.
Parameters:
| Name | Type | Description |
|---|---|---|
html |
string |
The HTML snippet or body content. |
Example:
| Method | Description | Typical Use Case |
|---|---|---|
text() |
Returns plain text content | API responses, logs |
data() |
Returns binary data | Files, JSON, images |
html() |
Returns a full HTML document | Web pages |
htmlBody() |
Returns an HTML fragment | Template rendering or partial updates |