HTTP Client: Simpler Streaming with Callbacks and Type-Safe Headers #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
HTTP Client: Simpler Streaming with Callbacks and Type-Safe Headers
What This Does
Makes HTTP streaming dramatically simpler by replacing manual selector loops with callbacks, while adding type safety for headers throughout the module.
Why These Changes
The Problem:
When streaming HTTP responses, users had to write 40+ lines of boilerplate:
This violated our ergonomics principles and didn't follow BEAM best practices (one process per concern).
Additionally, recordings were lost if
stop()wasn't called, and headers were untyped tuples throughout.The Solution:
Process-based streaming with callbacks + type-safe headers.
What Changed
New Streaming API (Breaking)
Before (2.x):
After (3.0):
New Functions:
start_stream()- Spawns dedicated process with callbackson_stream_start(),on_stream_chunk(),on_stream_end(),on_stream_error()- Builder callbacksawait_stream()- Wait for completioncancel_stream_handle(),is_stream_active()- Stream controlRemoved:
stream_messages()- now internalselect_stream_messages()- now internalHeader Type (Breaking)
Added
Header(name, value)type for type safety:get_headers()returnsList(Header)notList(#(String, String))StreamStart/StreamEnduseList(Header)add_header(name, value)still takes strings (builds Header internally)Immediate Recording Saves
recorder.stop()now optional (just cleanup)Documentation
test/snippets/with runnable examplesHow It Works
Each stream runs in its own BEAM process:
start_stream()spawns unlinked processstream_messages()to start HTTP streamYour mailbox stays clean. Your callbacks can send messages back to your actor if needed.
Testing
Migration
See CHANGELOG.md for detailed migration guide. Summary:
Headers: Use pattern matching with
Header(name, value)instead of#(name, value).Version: 3.0.0 (breaking)
Tests: 97 passing
Branch: feature/http-client-auto-record