httpp/jsonl
Use this to read newline delimites json streams
fn fetch() {
let subject = process.new_subject()
let request = uri.from_string("https://example.com/listen")
|> request.from_uri()
let decoder = {
use message <- decode.field("message", decode.string)
use sent_at <- decode.field("sent_at", decode.int)
decode.success(#(message, sent_at))
}
let mgr = json_lines_stream(request, 1000, decoder, subject)
// receive events just like any other message
let event = process.receive(subject, 1000)
}
Types
pub type JsonlEvent(datatype) {
Line(datatype)
Closed
}
Constructors
-
Line(datatype) -
Closed
pub type JsonlManagerMessage {
Shutdown
}
Constructors
-
Shutdown
Values
pub fn json_lines_stream(
req: request.Request(bytes_tree.BytesTree),
timeout: Int,
decoder: decode.Decoder(datatype),
subject: process.Subject(JsonlEvent(datatype)),
) -> Result(
process.Subject(JsonlManagerMessage),
actor.StartError,
)
Send a request to an endpoint that returns a newline delimited stream of json back on a subject you provide, decoded with your decoder. The timeout sets how long the actor will wait for the first response (status code, headers)