# Return an HTTP response to the caller

Publish / http

A variant of [Send to a web endpoint](https://meridian.online/operations/send-to-a-web-endpoint).

Build the status, headers and body of the response a pipeline served as a web service returns to the client that called it.

Page: <https://meridian.online/operations/send-to-a-web-endpoint/return-an-http-response>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

build the status, headers and body of a response for each request

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
CREATE TEMP TABLE requests AS SELECT * FROM (VALUES (1, 6), (2, 4), (3, 99)) t(request_id, order_id);
-- a found order is a 200 with its JSON; one that is not found is a 404 with an error body
CREATE TEMP TABLE responses AS
SELECT r.request_id,
       CASE WHEN o.order_id IS NULL THEN 404 ELSE 200 END AS status,
       CASE WHEN o.order_id IS NULL THEN to_json({'error': 'order ' || r.order_id || ' not found'})::VARCHAR
            ELSE to_json({'order_id': o.order_id, 'customer': o.customer, 'amount': o.amount})::VARCHAR END AS body
FROM requests r LEFT JOIN orders o USING (order_id);
CREATE TEMP TABLE result AS
SELECT request_id, status,
       MAP {'Content-Type': 'application/json; charset=utf-8', 'Content-Length': octet_length(encode(body))::VARCHAR} AS headers, body,
       'HTTP/1.1 ' || status || ' ' || CASE status WHEN 200 THEN 'OK' WHEN 404 THEN 'Not Found' END || chr(13) || chr(10)
         || 'Content-Type: application/json; charset=utf-8' || chr(13) || chr(10)
         || 'Content-Length: ' || octet_length(encode(body)) || chr(13) || chr(10) || chr(13) || chr(10) || body AS wire
FROM responses;
SELECT request_id, status, headers, body FROM result ORDER BY request_id;
SELECT CASE WHEN ((SELECT list(status ORDER BY request_id) FROM result) = [200, 200, 404] AND (SELECT headers['Content-Length'] FROM result WHERE request_id = 2) = '53' AND (SELECT wire FROM result WHERE request_id = 3) = 'HTTP/1.1 404 Not Found' || chr(13) || chr(10) || 'Content-Type: application/json; charset=utf-8' || chr(13) || chr(10) || 'Content-Length: 30' || chr(13) || chr(10) || chr(13) || chr(10) || '{"error":"order 99 not found"}' AND (SELECT body FROM result WHERE request_id = 2) = '{"order_id":4,"customer":"Carla Díaz","amount":null}') THEN 'as expected' ELSE error('the requests did not get a 200, a 200 and a 404 with a Content-Length counted in bytes and the response laid out as HTTP') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- EasyMorph: [`Construct HTTP response`](https://help.easymorph.com/doku.php?id=transformations:constructhttpresponse) (read 2026-09-27)
- KNIME Analytics Platform: [`Container Output (Raw HTTP)`](https://api.hub.knime.com/nodes/*XJQMSqH83dNbsnsQ?details=full) (read 2026-09-27)
- Apache NiFi: [`HandleHttpResponse`](https://nifi.apache.org/components/org.apache.nifi.processors.standard.HandleHttpResponse/) (read 2026-09-27)
- Talend: [`tAPIOperationResponse`](https://help.qlik.com/talend/en-US/components/8.0/esb-rest/esb-rest-component) (read 2026-09-27)
- Talend: [`tESBProviderResponse`](https://help.qlik.com/talend/en-US/components/8.0/esb-soap/esb-soap-component) (read 2026-09-27)
- Talend: [`tRESTResponse`](https://help.qlik.com/talend/en-US/components/8.0/esb-rest/esb-rest-component) (read 2026-09-27)
