[erlang-questions] Streaming Data using httpc

Paul Peregud paulperegud@REDACTED
Sun Apr 19 20:06:37 CEST 2015


I don't have experience using httpc, so one remark only:

receive_data(RequestId, State) ->
    receive
        {http, {RequestId, stream_start, Headers}} -> do something...,
receive_data(RequestId, State);
        {http, {RequestId, stream, Data}}               - > do
something..., receive_data(RequestId, State);
        {http, {RequestId, stream_end, Headers}}   -> do something...
    end.

Because you want to exit receive_data when no more data is going your way.


On Sun, Apr 19, 2015 at 5:30 PM, John Duffy <jb_duffy@REDACTED> wrote:
> 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
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



-- 
Best regards,
Paul Peregud
+48602112091



More information about the erlang-questions mailing list