Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module replicates `pipes-http` as closely as will type-check.
Here is an example GET request that streams the response body to standard output:
import qualified Data.ByteString.Streaming as S import Data.ByteString.Streaming.HTTP main = do req <- parseUrl "https://www.example.com" m <- newManager tlsManagerSettings withHTTP req m $ \resp -> S.stdout (responseBody resp)
Here is an example POST request that also streams the request body from standard input:
{-#LANGUAGE OverloadedStrings #-} import qualified Data.ByteString.Streaming as S import Data.ByteString.Streaming.HTTP main = do req <- parseUrl "https://www.example.com" let req' = req { method = "POST" , requestBody = stream S.stdin } m <- newManager tlsManagerSettings withHTTP req' m $ \resp -> S.stdout (responseBody resp)
For non-streaming request bodies, study the RequestBody
type, which also
accepts strict / lazy bytestrings or builders.
- module Network.HTTP.Client.TLS
- withHTTP :: Request -> Manager -> (Response (ByteString IO ()) -> IO a) -> IO a
- streamN :: Int64 -> ByteString IO () -> RequestBody
- stream :: ByteString IO () -> RequestBody
http-client
This module is a thin streaming-bytestring
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.TLS
Streaming Interface
:: Request | |
-> Manager | |
-> (Response (ByteString IO ()) -> IO a) | Handler for response |
-> IO a |
Send an HTTP Request
and wait for an HTTP Response
streamN :: Int64 -> ByteString IO () -> RequestBody Source
Create a RequestBody
from a content length and an effectful ByteString
stream :: ByteString IO () -> RequestBody Source
Create a RequestBody
from an effectful ByteString
stream
is more flexible than streamN
, but requires the server to support
chunked transfer encoding.