Safe Haskell | None |
---|---|
Language | Haskell2010 |
System.IO.Streams.HTTP
Contents
Description
Here is an example GET request that streams the response body to standard output:
import System.IO.Streams (InputStream, OutputStream) import qualified System.IO.Streams as Streams import System.IO.Streams.HTTP import Network.HTTP.Client main :: IO () main = do req <- parseUrl "http://google.com" withManager defaultManagerSettings $ \m -> withHTTP req m $ \resp -> do Streams.handleToOutputStream stdout >>= Streams.connect (responseBody resp)
Here is an example POST request that also streams the request body from standard input:
{-# LANGUAGE OverloadedStrings #-} module Main where import System.IO.Streams ( InputStream, OutputStream ) import qualified System.IO.Streams as Streams import System.IO.Streams.HTTP ( withHTTP, parseUrl, withManager, stream ) import Network.HTTP.Client.TLS ( tlsManagerSettings ) import Network.HTTP.Client ( responseBody ) bodyTest :: IO () bodyTest = do req <- parseUrl "https://google.com" let request = req { method = "POST" , requestBody = stream $ Streams.fromLazyByteString "body" } withManager tlsManagerSettings $ \m -> withHTTP req m $ \resp -> do Streams.supplyTo Streams.stdout (responseBody resp)
For non-streaming request bodies, study the RequestBody
type,
which also
accepts strict / lazy bytestrings
- module Network.HTTP.Client
- module Network.HTTP.Client.TLS
- withHTTP :: Request -> Manager -> (Response (InputStream ByteString) -> IO a) -> IO a
- streamN :: Int64 -> IO (InputStream ByteString) -> RequestBody
- stream :: IO (InputStream ByteString) -> RequestBody
http-client
This module is a thin io-streams
wrapper around the http-client
and
http-client-tls
libraries.
If you're looking for openssl please us this library https://hackage.haskell.org/package/http-client-streams
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
io-streams Interface
withHTTP :: Request -> Manager -> (Response (InputStream ByteString) -> IO a) -> IO a Source
streamN :: Int64 -> IO (InputStream ByteString) -> RequestBody Source
Stream with N bytes exactly
stream :: IO (InputStream ByteString) -> RequestBody Source
Stream body of request