HTTP Stream RFC
XIDL HTTP Stream Mapping Specification
Section titled “XIDL HTTP Stream Mapping Specification”This profile defines structured, one-directional HTTP streams. It reuses HTTP operation types and exceptions; it introduces no additional IDL syntax.
Operation Model
Section titled “Operation Model”| Annotation | Direction | Default method | Default codec |
|---|---|---|---|
@server_stream |
One request, multiple response items | GET | SSE |
@client_stream |
Multiple request items, one response | POST | NDJSON |
An operation’s return type describes one server-stream item. Client-stream items use the generated request type containing the operation’s input members. A sequence type represents a batch within each item; it is not required to declare a stream. Standard HTTP path and security annotations still apply.
@http(409) exception Conflict { string reason; };struct Row { string id; int32 quantity; };interface Ledger { @server_stream @get(path = "/exports") Row export_rows() raises(Conflict);
@client_stream @post(path = "/imports") int32 import_rows(in Row row) raises(Conflict);};The Rust, Go, and TypeScript REST targets support structured SSE server streams and NDJSON client streams. An explicit codec selection does not imply that every target supports that combination; unsupported combinations fail generation.
Frames
Section titled “Frames”Frames separate business data from stream control. A reader ignores heartbeat
frames and never yields control frames as application data. A next frame must
contain data, even when its value is zero, false, or null.
SSE Responses
Section titled “SSE Responses”The response content type is text/event-stream. Events end with an empty line:
: heartbeat
event: nextdata: {"id":"r1","quantity":0}
event: completedata: {}Comments and empty event blocks are ignored. An unterminated event at EOF does not count as a received frame. Completion includes a data line so standard SSE consumers dispatch the event. Sending heartbeats is application/runtime policy.
NDJSON Requests
Section titled “NDJSON Requests”The request content type is application/x-ndjson. Each line is a frame:
{"t":"heartbeat"}{"t":"next","seq":1,"data":{"row":{"id":"r1","quantity":0}}}{"t":"complete"}seq is optional transport metadata; it does not provide replay, deduplication,
or ordering guarantees across requests. Empty lines are ignored. A bare JSON
business value is not a framed stream item.
When updating from runtimes that sent bare NDJSON values, regenerate the SDKs and update both endpoints together. This profile requires control frames.
Terminal Outcomes
Section titled “Terminal Outcomes”Each structured stream has one immutable terminal outcome:
| Outcome | Trigger |
|---|---|
| Completed | A complete frame is received |
| Failed | An error frame is received, or the producer cannot encode an item |
| Cancelled | The consumer explicitly cancels or drops the stream |
| Interrupted | Transport EOF, malformed framing, or disconnection without a terminal frame |
A producer sends exactly one terminal frame, either complete or error. An error is never followed by complete. Readers stop at the first terminal frame and release the body; appended frames cannot become additional business items. Cleanup cannot overwrite a terminal outcome. EOF without a terminal frame is reported as an error, including for an otherwise empty stream.
Consumers must propagate stream-read errors and consume through completion before treating an import/export as successful. Cancellation does not imply transaction rollback. Storage atomicity remains the application’s responsibility.
Exceptions and the First Output Boundary
Section titled “Exceptions and the First Output Boundary”A structured stream can declare the same raises(...) exceptions as a unary
operation. HTTP exception status codes must uniquely identify the operation’s
declared exceptions. The error channel uses the existing 300 through 599 status
range, including bodyless 304 exceptions. Generated codecs use the exception set
of the selected API version.
The boundary is the first serialized output, not merely obtaining the first business value:
- Before output is committed, failures use the ordinary HTTP exception status and JSON body. An item serialization failure produces an HTTP error.
- After output is committed, failures use one terminal error frame. An item serialization failure produces a runtime error frame, never a fabricated null item. The producer stops reading the source after failure.
The in-band error carries the same status and projected JSON body as HTTP:
event: errordata: {"status":409,"body":{"reason":"locked"}}The corresponding NDJSON frame is:
{"t":"error","error":{"status":409,"body":{"reason":"locked"}}}A bodyless exception uses body: null in a frame. Exceptions with header or
cookie members are rejected for streams because those members cannot be sent
after the HTTP headers have been committed. Undeclared runtime errors remain
runtime errors; they are not converted into an arbitrary declared exception.
Go writers flush every frame. Proxies and hosting adapters must permit streaming and avoid buffering. Generated readers do not transparently retry failed streams.
Separate Protocols
Section titled “Separate Protocols”A sole sequence<octet> stream payload uses raw application/octet-stream
bytes. It has no control frames: transport EOF remains the end of the byte
stream. Raw response streams cannot declare raises(...); raw uploads can use
declared exceptions in their ordinary HTTP response.
@bidi_stream and WebSocket @upgrade use their own close protocol, documented
in the HTTP Upgrade / WebSocket RFC. They do not support
stream raises(...) in this profile.
Retries, replay cursors, version conversion of frames, heartbeat scheduling, authentication refresh, and delivery guarantees belong to separate capabilities or application policy. See HTTP Streaming for generated APIs.