BlocksNetwork
http response
Send the HTTP response for a request that started with an `http in` block.
http response Block
The http response block is used to send HTTP responses back to clients, completing API workflows started by http in blocks. It's essential for creating REST APIs and web services with AIStudio.
Overview
The http response block completes the request-response cycle started by http in.
Its editor configuration exposes:
namestatusCodeheaders
This node has one input and no outputs.
What it reads from the message
The block primarily uses:
msg.payload: response bodymsg.res: response object created byhttp inmsg.statusCode: optional runtime status codemsg.headers: optional runtime headersmsg.cookies: optional cookies to set or clear
Response behavior
- The final status code is:
- the node's configured
statusCode, if set - otherwise
msg.statusCode, if set - otherwise
200
- the node's configured
- Configured headers are applied first.
- Headers in
msg.headersare merged in if the same header is not already configured on the node. - If
msg.payloadis an object and not a buffer, the node sends it as JSON/JSONP. - If
msg.payloadis a string, number, buffer, ornull, the node sends it as the raw body.
Cookies
If msg.cookies is present, the block will set or clear cookies on the response.
Typical shapes:
- set cookie:
msg.cookies.session = "abc123" - set cookie with options:
msg.cookies.session = { value: "abc123", httpOnly: true } - clear cookie:
msg.cookies.session = null
Example
Input message
{
"payload": {
"status": "success",
"document_id": "doc-1001"
},
"statusCode": 201,
"headers": {
"Content-Type": "application/json"
},
"res": {}
}HTTP response sent
HTTP/1.1 201 Created
Content-Type: application/json
{
"status": "success",
"document_id": "doc-1001"
}File and binary responses
To return a file or binary payload:
- put the binary data in
msg.payload - set headers such as
Content-Type - optionally set
Content-Disposition
Example input
{
"headers": {
"Content-Type": "application/pdf",
"Content-Disposition": "attachment; filename=result.pdf"
}
}Limitations
- This block only works when
msg.resis present, which normally means the flow started fromhttp in. - It has no downstream output.
- If you send a plain object, the node treats it as JSON rather than raw text.
Common mistakes
- Using
http responsein a flow that did not start fromhttp in. - Forgetting to set file-related headers for binary downloads.
- Expecting
msg.headersto override headers already configured on the node. - Setting neither a configured status code nor
msg.statusCodewhen a non-200response is required.