Safe Haskell | None |
---|---|
Language | Haskell98 |
Pipes.HTTP
Contents
Description
Here is an example GET request that streams the response body to standard output:
import Pipes import Pipes.HTTP import qualified Pipes.ByteString as PB -- from `pipes-bytestring` main = do req <- parseUrlThrow "https://www.example.com" manager <- withManager tlsManagerSettings withHTTP req manager $ \resp -> runEffect $ responseBody resp >-> PB.stdout
Here is an example POST request that also streams the request body from standard input:
{-# LANGUAGE OverloadedStrings #-} import Pipes import Pipes.HTTP import qualified Pipes.ByteString as PB main = do req <- parseUrlThrow "https://www.example.com" let req' = req { method = "POST" , requestBody = stream PB.stdin } manager <- newManager tlsManagerSettings withHTTP req' manager $ \resp -> runEffect $ responseBody resp >-> PB.stdout
For non-streaming request bodies, study the RequestBody
type, which also
accepts strict / lazy bytestrings or builders.
Synopsis
- module Network.HTTP.Client
- module Network.HTTP.Client.TLS
- withHTTP :: Request -> Manager -> (Response (Producer ByteString IO ()) -> IO a) -> IO a
- streamN :: Int64 -> Producer ByteString IO () -> RequestBody
- stream :: Producer ByteString IO () -> RequestBody
http-client
This module is a thin pipes
wrapper around the http-client
and
http-client-tls
libraries.
Read the documentation in the Network.HTTP.Client module of the
http-client
library to learn about how to:
- manage connections using connection pooling,
- use more advanced request/response features,
- handle exceptions, and:
- manage cookies.
http-client-tls
provides support for TLS connections (i.e. HTTPS).
module Network.HTTP.Client
module Network.HTTP.Client.TLS
Pipes Interface
streamN :: Int64 -> Producer ByteString IO () -> RequestBody Source #
Create a RequestBody
from a content length and Producer
stream :: Producer ByteString IO () -> RequestBody Source #
Create a RequestBody
from a Producer
stream
is more flexible than streamN
, but requires the server to support
chunked transfer encoding.