polysemy-http-0.1.0.0: Polysemy effect for http-client
Safe HaskellNone
LanguageHaskell2010

Polysemy.Http.Http

Synopsis

Documentation

streamLoop :: Members [Http c, Error HttpError] r => (forall x. StreamEvent o c h x -> Sem r x) -> Response c -> h -> Sem r o Source #

streamHandler :: forall o r c h. Members [Http c, Error HttpError, Resource] r => (forall x. StreamEvent o c h x -> Sem r x) -> Response c -> Sem r o Source #

streamResponse :: Members [Http c, Error HttpError, Resource] r => Request -> (forall x. StreamEvent o c h x -> Sem r x) -> Sem r o Source #

Initiate a request and stream the response, calling process after connecting, for every chunk, after closing the connection, and for the return value. StreamEvent is used to indicate the stage of the request cycle.

handle ::
  StreamEvent Double (IO ByteString) Int a ->
  Sem r a
handle = \case
  StreamEvent.Acquire (Response status body headers) ->
    pure 1
  StreamEvent.Chunk handle (StreamChunk c) ->
    pure ()
  StreamEvent.Result (Response status body headers) handle ->
    pure 5.5
  StreamEvent.Release handle ->
    pure ()
>>> runInterpreters $ streamResponse (Http.get "host.com" "path/to/file") handle
5.5