Hoogle Search

Within LTS Haskell 24.52 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. ReqBodyLbs :: ByteString -> ReqBodyLbs

    req Network.HTTP.Req

    No documentation available.

  2. data ReqBodyMultipart

    req Network.HTTP.Req

    Multipart form data. Please consult the Network.HTTP.Client.MultipartFormData module for how to construct parts, then use reqBodyMultipart to create actual request body from the parts. reqBodyMultipart is the only way to get a value of the type ReqBodyMultipart, as its constructor is not exported on purpose.

    Examples

    import Control.Monad.IO.Class
    import Data.Default.Class
    import Network.HTTP.Req
    import qualified Network.HTTP.Client.MultipartFormData as LM
    
    main :: IO ()
    main = runReq def $ do
    body <-
    reqBodyMultipart
    [ LM.partBS "title" "My Image"
    , LM.partFileSource "file1" "/tmp/image.jpg"
    ]
    response <-
    req POST (http "example.com" /: "post")
    body
    bsResponse
    mempty
    liftIO $ print (responseBody response)
    

  3. newtype ReqBodyUrlEnc

    req Network.HTTP.Req

    URL-encoded body. This can hold a collection of parameters which are encoded similarly to query parameters at the end of query string, with the only difference that they are stored in request body. The similarity is reflected in the API as well, as you can use the same combinators you would use to add query parameters: (=:) and queryFlag. This body option sets the Content-Type header to "application/x-www-form-urlencoded" value.

  4. ReqBodyUrlEnc :: FormUrlEncodedParam -> ReqBodyUrlEnc

    req Network.HTTP.Req

    No documentation available.

  5. getRequestBody :: HttpBody body => body -> RequestBody

    req Network.HTTP.Req

    How to get actual RequestBody.

  6. getRequestContentType :: HttpBody body => body -> Maybe ByteString

    req Network.HTTP.Req

    This method allows us to optionally specify the value of Content-Type header that should be used with particular body option. By default it returns Nothing and so Content-Type is not set.

  7. req :: forall m method body response (scheme :: Scheme) . (MonadHttp m, HttpMethod method, HttpBody body, HttpResponse response, HttpBodyAllowed (AllowsBody method) (ProvidesBody body)) => method -> Url scheme -> body -> Proxy response -> Option scheme -> m response

    req Network.HTTP.Req

    Make an HTTP request. The function takes 5 arguments, 4 of which specify required parameters and the final Option argument is a collection of optional parameters. Let's go through all the arguments first: req method url body response options. method is an HTTP method such as GET or POST. The documentation has a dedicated section about HTTP methods below. url is a Url that describes location of resource you want to interact with. body is a body option such as NoReqBody or ReqBodyJson. The tutorial has a section about HTTP bodies, but usage is very straightforward and should be clear from the examples. response is a type hint how to make and interpret response of an HTTP request. Out-of-the-box it can be the following:

    Finally, options is a Monoid that holds a composite Option for all other optional settings like query parameters, headers, non-standard port number, etc. There are quite a few things you can put there, see the corresponding section in the documentation. If you don't need anything at all, pass mempty. Note that if you use req to do all your requests, connection sharing and reuse is done for you automatically. See the examples below to get on the speed quickly.

    Examples

    First, this is a piece of boilerplate that should be in place before you try the examples:
    {-# LANGUAGE DeriveGeneric     #-}
    {-# LANGUAGE OverloadedStrings #-}
    
    module Main (main) where
    
    import Control.Monad
    import Control.Monad.IO.Class
    import Data.Aeson
    import Data.Maybe (fromJust)
    import Data.Monoid ((<>))
    import Data.Text (Text)
    import GHC.Generics
    import Network.HTTP.Req
    import qualified Data.ByteString.Char8 as B
    import qualified Text.URI as URI
    
    We will be making requests against the https://httpbin.org service. Make a GET request, grab 5 random bytes:
    main :: IO ()
    main = runReq defaultHttpConfig $ do
    let n :: Int
    n = 5
    bs <- req GET (https "httpbin.org" /: "bytes" /~ n) NoReqBody bsResponse mempty
    liftIO $ B.putStrLn (responseBody bs)
    
    The same, but now we use a query parameter named "seed" to control seed of the generator:
    main :: IO ()
    main = runReq defaultHttpConfig $ do
    let n, seed :: Int
    n    = 5
    seed = 100
    bs <- req GET (https "httpbin.org" /: "bytes" /~ n) NoReqBody bsResponse $
    "seed" =: seed
    liftIO $ B.putStrLn (responseBody bs)
    
    POST JSON data and get some info about the POST request:
    data MyData = MyData
    { size  :: Int
    , color :: Text
    } deriving (Show, Generic)
    
    instance ToJSON MyData
    instance FromJSON MyData
    
    main :: IO ()
    main = runReq defaultHttpConfig $ do
    let myData = MyData
    { size  = 6
    , color = "Green" }
    v <- req POST (https "httpbin.org" /: "post") (ReqBodyJson myData) jsonResponse mempty
    liftIO $ print (responseBody v :: Value)
    
    Sending URL-encoded body:
    main :: IO ()
    main = runReq defaultHttpConfig $ do
    let params =
    "foo" =: ("bar" :: Text) <>
    queryFlag "baz"
    response <- req POST (https "httpbin.org" /: "post") (ReqBodyUrlEnc params) jsonResponse mempty
    liftIO $ print (responseBody response :: Value)
    
    Using various optional parameters and URL that is not known in advance:
    main :: IO ()
    main = runReq defaultHttpConfig $ do
    -- This is an example of what to do when URL is given dynamically. Of
    -- course in a real application you may not want to use 'fromJust'.
    uri <- URI.mkURI "https://httpbin.org/get?foo=bar"
    let (url, options) = fromJust (useHttpsURI uri)
    response <- req GET url NoReqBody jsonResponse $
    "from" =: (15 :: Int)           <>
    "to"   =: (67 :: Int)           <>
    basicAuth "username" "password" <>
    options                         <> -- contains the ?foo=bar part
    port 443 -- here you can put any port of course
    liftIO $ print (responseBody response :: Value)
    

  8. req' :: forall m method body (scheme :: Scheme) a . (MonadHttp m, HttpMethod method, HttpBody body, HttpBodyAllowed (AllowsBody method) (ProvidesBody body)) => method -> Url scheme -> body -> Option scheme -> (Request -> Manager -> m a) -> m a

    req Network.HTTP.Req

    Mostly like req with respect to its arguments, but accepts a callback that allows to perform a request in arbitrary fashion. This function does not perform handling/wrapping exceptions, checking response (with httpConfigCheckResponse), and retrying. It only prepares Request and allows you to use it.

  9. reqBodyMultipart :: MonadIO m => [Part] -> m ReqBodyMultipart

    req Network.HTTP.Req

    Create ReqBodyMultipart request body from a collection of Parts.

  10. reqBr :: forall m method body (scheme :: Scheme) a . (MonadHttp m, HttpMethod method, HttpBody body, HttpBodyAllowed (AllowsBody method) (ProvidesBody body)) => method -> Url scheme -> body -> Option scheme -> (Response BodyReader -> IO a) -> m a

    req Network.HTTP.Req

    A version of req that does not use one of the predefined instances of HttpResponse but instead allows the user to consume Response BodyReader manually, in a custom way.

Page 315 of many | Previous | Next