[erlang-questions] Streaming Data using httpc

John Duffy jb_duffy@REDACTED
Sun Apr 19 17:30:40 CEST 2015


Hi
I'm new to Erlang so please forgive my ignorance. I'm trying to stream data from a REST API using httpc, and although I have scoured the internet and the documentation I can't find a good example of how to do this, in particular how the "sync" and "receiver" options interoperate. My unsuccessful module looks like this...
-module(streaming).
-export([data/0]). 
data() ->
    {ok, RequestId} = httpc:request(get, {"http://my_streaming_data_source.com", []}, [], [{sync, false}, {receiver, self()]),
    receive_data(RequestId).
receive_data(RequestId) ->
    receive
        {http, {RequestId, stream_start, Headers}} -> do something...; 
        {http, {RequestId, stream, Data}}               - > do something...; 
        {http, {RequestId, stream_end, Headers}}   -> do something...;
    end,
    receive_data(RequestId).
Is the above how I should be structuring my module?
Kind regards
John Duffy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150419/28d31bfd/attachment.htm>


More information about the erlang-questions mailing list