Skip to content

Response Block

The Response block marks where the API response originates in a synchronous workflow. It defines the output that gets sent back to the API caller. If there are multiple Response blocks, the first one to receive a message determines the API response.

AWS Service: Amazon API Gateway


Configuration Options

The Response block has no additional configuration options. It serves as an endpoint marker that captures the output from the connected Function block.


How It Works

  1. An API Trigger receives an HTTP request
  2. The workflow processes through Function blocks
  3. The Response block receives the final output
  4. API Gateway returns this output to the caller
API Trigger --> Function --> Function --> Response
                                             |
                                             v
                                      Returns to caller

Requirements

API Trigger Requirement

The Response block only works when:

  • The workflow starts with an API Trigger or a WebSocket Trigger block
  • The API Trigger has isSynchronous set to true

Async APIs

If isSynchronous is false, the API returns immediately. The Response block output is ignored.


Response Format

The Response block returns whatever data the connected Function sends:

Simple String Response

// In your Function block
send("Hello, World!");

Returns:

"Hello, World!"

JSON Object Response

// In your Function block
send({
  status: "success",
  data: {
    id: 123,
    name: "Example"
  }
});

Returns:

{
  "status": "success",
  "data": {
    "id": 123,
    "name": "Example"
  }
}

Custom HTTP Status Codes

To return custom status codes, structure your response with statusCode and body:

// Return a 201 Created
send("accpeted", { statusCode: 201});

// Return a 404 Not Found
send("user not found", { statusCode: 404});

AWS Reference


Example Usage

Basic API Response

API Trigger (/users/{id}, GET) --> Function (fetch user) --> Response
// Function block code
const userId = input.payload.pathParameters.id;
const user = await getUser(userId);

if (user) {
  send(user);
} else {
  send({ error: "User not found" }, { statusCode: 404 });
}

Best Practices

  1. Always connect to synchronous APIs: Response only works with isSynchronous: true
  2. Return consistent formats: Use consistent JSON structures for all responses
  3. Include error handling: Return appropriate status codes for errors
  4. Keep responses small: Large responses increase latency and costs