Skip to content

Practical guide

Set API response status codes and headers

Configure successful Twidget API responses, choose between 200, 201, 202 and 204, and verify the published status, headers and body together.

1. Match the status to the completed work

A response status is part of the contract your frontend or integration consumes. Start with a synthetic endpoint whose output you understand. Twidget lets you configure successful response status and additional headers in the endpoint Output editor. Error responses retain their own status; choosing a success status does not replace validation or error handling.

StatusUse when your workflow establishes this result
200The operation succeeded and may return a body
201A new resource was created
202Work was accepted and completion is still pending
204The operation succeeded with no response body

Returning 202 does not itself create a queue or run work asynchronously. Only use it when your implementation supports that behavior.

2. Set the successful response in Output

Open the endpoint's Output editor, select RESPONSE and choose the intended status. The documented default when left blank is 200. If a command variable controls the status, inspect every possible value and establish a safe contract for each branch.

For a create endpoint returning 201, map an explicit safe result containing the created record's identifier. Do not pass through the entire authentication record or internal command output. Use the CRUD guide to review generated inputs and output before adapting them.

Output RESPONSE editor with status 202 and an X-Acceptance header
Existing maintained-documentation capture of successful response settings. Its sample header is database-upgrades; it does not show the new sample-v1 example being configured.

3. Add only the headers your client needs

Add a response-headers object in the same editor. A harmless example is {"X-App-Revision":"sample-v1"}. A dynamic value can reference a workflow variable, but it must not contain secrets, bearer tokens or internal exception details.

Some headers, including cookie, browser-access and tracing headers, are reserved here. Use the appropriate API settings for browser access rather than trying to override them through this object. For a frontend integration, check the browser request and CORS workflow. Custom headers do not automatically make a browser response readable.

4. Make the body agree with the status

For 200 or 201, define the exact fields the client needs. For 204 and 205, do not expect a response body. A client that always calls JSON parsing will fail on a successful empty response. Either handle that status before parsing or return a suitable body-bearing status for your chosen contract.

A failure must not look like a successful empty list. Use validation and the workflow's error handling for denied or invalid requests. The validation guide covers those branches; changing a success status alone is insufficient.

5. Inspect the actual HTTP response

Save, test and publish the endpoint. In the API client, call its published path with synthetic input and inspect status, headers and raw body. A successful isolated command test does not establish the published HTTP contract. Watch the API client tutorial for request setup.

Verify a successful creation, a validation failure, a denied request and an empty-body success if used. Confirm the error branches keep appropriate errors and never inherit a misleading success status. If a header is missing, check reserved-header rules, output mapping and published state.

API suite editor with a create_request step alias
Existing Marketing test controls. Use dedicated fixtures for this guide; this screenshot does not demonstrate its acceptance cases.
API client status displaying HTTP 202 Accepted
Existing documentation sample returned HTTP 202 Accepted. This verifies that documented sample only; the new endpoint contract remains your acceptance check.

6. Update clients before changing an established contract

List consumers that assume status 200 or a JSON body before switching a live endpoint to 201 or 204. Update their success handling and regression tests deliberately. An HTTP-correct change can still break a client that was written against the old response.

Use API workflow tests to cover the complete create/read journey, and review changes in Dev-to-Prod promotion. The status should describe the operation you have verified, not a future step the workflow has not performed.

Go deeper

Supporting documentation

Find the configuration details and reference material behind this page.

From idea to a working flow

Build one useful thing with Twidget

Start with a small workflow, test it with sample data and make it your own.

Preview

Have any questions? Get in Touch

Starting with Twidget is easy, fast and free

It only takes a few clicks to get started

Get started - it's free

No credit card required.


© Copyright 2026 - Twidget.io