dream_http_client/recording
Recording format types and JSON codecs
Defines the structure for storing HTTP request/response recordings in a custom JSON format that supports both blocking and streaming responses.
Types
Streaming chunk with timing information
pub type Chunk {
Chunk(data: BitArray, delay_ms: Int)
}
Constructors
-
Chunk(data: BitArray, delay_ms: Int)
Recorded HTTP request
pub type RecordedRequest {
RecordedRequest(
method: http.Method,
scheme: http.Scheme,
host: String,
port: option.Option(Int),
path: String,
query: option.Option(String),
headers: List(#(String, String)),
body: String,
)
}
Constructors
-
RecordedRequest( method: http.Method, scheme: http.Scheme, host: String, port: option.Option(Int), path: String, query: option.Option(String), headers: List(#(String, String)), body: String, )
Recorded HTTP response - can be blocking or streaming
pub type RecordedResponse {
BlockingResponse(
status: Int,
headers: List(#(String, String)),
body: String,
)
StreamingResponse(
status: Int,
headers: List(#(String, String)),
chunks: List(Chunk),
)
}
Constructors
-
BlockingResponse( status: Int, headers: List(#(String, String)), body: String, ) -
StreamingResponse( status: Int, headers: List(#(String, String)), chunks: List(Chunk), )
Complete recording entry (request + response pair)
pub type Recording {
Recording(request: RecordedRequest, response: RecordedResponse)
}
Constructors
-
Recording(request: RecordedRequest, response: RecordedResponse)
Values
pub fn decode_recording_file(
json_string: String,
) -> Result(RecordingFile, String)
Decode a JSON string into a RecordingFile
Parses the given JSON string and attempts to decode it into a
RecordingFile value. This is the inverse of encode_recording_file/1 and
is used by the storage module when loading recordings from disk.
On success, returns the decoded RecordingFile. On failure, returns a
human-readable error message describing why the JSON could not be parsed or
decoded.
pub fn encode_recording_file(file: RecordingFile) -> json.Json
Encode a RecordingFile to JSON
This helper converts an in-memory RecordingFile value into a json.Json
tree that can be rendered to a string and written to disk. It is used by
the storage module when persisting recordings.
Most callers should use storage.save_recordings/2 instead of calling this
function directly.