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
- An API Trigger receives an HTTP request
- The workflow processes through Function blocks
- The Response block receives the final output
- API Gateway returns this output to the 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
isSynchronousset totrue
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
Returns:
JSON Object Response
Returns:
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
// 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
- Always connect to synchronous APIs: Response only works with
isSynchronous: true - Return consistent formats: Use consistent JSON structures for all responses
- Include error handling: Return appropriate status codes for errors
- Keep responses small: Large responses increase latency and costs