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:

  • name
  • statusCode
  • headers

This node has one input and no outputs.

What it reads from the message

The block primarily uses:

  • msg.payload: response body
  • msg.res: response object created by http in
  • msg.statusCode: optional runtime status code
  • msg.headers: optional runtime headers
  • msg.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
  • Configured headers are applied first.
  • Headers in msg.headers are merged in if the same header is not already configured on the node.
  • If msg.payload is an object and not a buffer, the node sends it as JSON/JSONP.
  • If msg.payload is a string, number, buffer, or null, 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.res is present, which normally means the flow started from http 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 response in a flow that did not start from http in.
  • Forgetting to set file-related headers for binary downloads.
  • Expecting msg.headers to override headers already configured on the node.
  • Setting neither a configured status code nor msg.statusCode when a non-200 response is required.