req-3.13.4: HTTP client library

Copyright | © 2016–present Mark Karpov
License | BSD 3 clause
Maintainer | Mark Karpov <markkarpov92@gmail.com>
Stability | experimental
Portability | portable
Safe Haskell | None
Language | GHC2021

Network.HTTP.Req

Contents

- Making a request
- Embedding requests in your monad
- Request
  - Method
  - URL
  - Body
  - Optional parameters
    - Query parameters
    - Headers
    - Cookies
    - Authentication
    - Other
- Response
  - Response interpretations
  - Inspecting a response
  - Defining your own interpretation
- Other

Description

The documentation below is structured in such a way that the most important information is presented first: you learn how to do HTTP requests, how to embed them in the monad you have, and then it gives you details about less-common things you may want to know about. The documentation is written with sufficient coverage of details and examples, and it's designed to be a complete tutorial on its own.

### About the library

Req is an HTTP client library that attempts to be easy-to-use, type-safe, and expandable.

“Easy-to-use” means that the library is designed to be beginner-friendly so it's simple to add to your monad stack, intuitive to work with, well-documented, and does not get in your way. Doing HTTP requests is a common task and a Haskell library for this should be approachable and clear to beginners, thus certain compromises were made. For example, one cannot currently modify `ManagerSettings` of the default manager because the library always uses the same implicit global manager for simplicity and maximal connection sharing. There is a way to use your own manager with different settings, but it requires more typing.

“Type-safe” means that the library tries to eliminate certain classes of errors. For example, we have correct-by-construction URLs; it is guaranteed that the user does not send the request body when using methods like GET or OPTIONS, and the amount of implicit assumptions is minimized by making the user specify their intentions in an explicit form. For example, it's not possible to avoid specifying the body or the method of a request. Authentication methods that assume HTTPS force the user to use HTTPS at the type level.

“Expandable” refers to the ability to create new components without having to resort to hacking. For example, it's possible to define your own HTTP methods, create new ways to construct the body of a request, create new authorization options, perform a request in a different way, and create your own methods to parse a response.

### Using with other libraries

- You won't need the low-level interface of `http-client` most of the time, but when you do, it's better to do a qualified import, because `http-client` has naming conflicts with `req`.
- For streaming of large request bodies see the companion package `req-conduit`: https://hackage.haskell.org/package/req-conduit.

### Lightweight, no risk solution

The library uses the following mature packages under the hood to guarantee you the best experience:

- https://hackage.haskell.org/package/http-client—low level HTTP client used everywhere in Haskell.
- https://hackage.haskell.org/package/http-client-tls—TLS (HTTPS) support for `http-client`.

It's important to note that since we leverage well-known libraries that the whole Haskell ecosystem uses, there is no risk in using `req`. The machinery for performing requests is the same as with `http-conduit` and `wreq`. The only difference is the API.

Synopsis

- 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
- 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
- reqCb :: 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 -> (Request -> m Request) -> m response
- 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
- withReqManager :: MonadIO m => (Manager -> m a) -> m a
- class MonadIO m => MonadHttp (m :: Type -> Type) where
  - handleHttpException :: HttpException -> m a
  - getHttpConfig :: m HttpConfig
- data HttpConfig = HttpConfig {
  - httpConfigProxy :: Maybe Proxy
  - httpConfigRedirectCount :: Int
  - httpConfigAltManager :: Maybe Manager
  - httpConfigCheckResponse :: forall b. Request -> Response b -> ByteString -> Maybe HttpExceptionContent
  - httpConfigRetryPolicy :: RetryPolicyM IO
  - httpConfigRetryJudge :: forall b. RetryStatus -> Response b -> Bool
  - httpConfigRetryJudgeException :: RetryStatus -> SomeException -> Bool
  - httpConfigBodyPreviewLength :: forall a. Num a => a
  }
- defaultHttpConfig :: HttpConfig
- data Req a
- runReq :: MonadIO m => HttpConfig -> Req a -> m a
- data GET = GET
- data POST = POST
- data HEAD = HEAD
- data PUT = PUT
- data DELETE = DELETE
- data TRACE = TRACE
- data CONNECT = CONNECT
- data OPTIONS = OPTIONS
- data PATCH = PATCH
- class HttpMethod (a :: k) where
  - type AllowsBody (a :: k) :: CanHaveBody
  - httpMethodName :: Proxy a -> ByteString
- data Url (scheme :: Scheme)
- http :: Text -> Url 'Http
- https :: Text -> Url 'Https
- (/~) :: forall a (scheme :: Scheme). ToHttpApiData a => Url scheme -> a -> Url scheme
- (/:) :: forall (scheme :: Scheme). Url scheme -> Text -> Url scheme
- useHttpURI :: forall (scheme :: Scheme). URI -> Maybe (Url 'Http, Option scheme)
- useHttpsURI :: forall (scheme :: Scheme). URI -> Maybe (Url 'Https, Option scheme)
- useURI :: forall (scheme0 :: Scheme) (scheme1 :: Scheme). URI -> Maybe (Either (Url 'Http, Option scheme0) (Url 'Https, Option scheme1))
- urlQ :: QuasiQuoter
- renderUrl :: forall (scheme :: Scheme). Url scheme -> Text
- data NoReqBody = NoReqBody
- newtype ReqBodyJson a = ReqBodyJson a
- newtype ReqBodyFile = ReqBodyFile FilePath
- newtype ReqBodyBs = ReqBodyBs ByteString
- newtype ReqBodyLbs = ReqBodyLbs ByteString
- newtype ReqBodyUrlEnc = ReqBodyUrlEnc FormUrlEncodedParam
- data FormUrlEncodedParam
- data ReqBodyMultipart
- reqBodyMultipart :: MonadIO m => [Part] -> m ReqBodyMultipart
- class HttpBody body where
  - getRequestBody :: body -> RequestBody
  - getRequestContentType :: body -> Maybe ByteString
- type family ProvidesBody body :: CanHaveBody where ...
- type family HttpBodyAllowed (allowsBody :: CanHaveBody) (providesBody :: CanHaveBody) where ...
- data Option (scheme :: Scheme)
- (=:) :: (QueryParam param, ToHttpApiData a) => Text -> a -> param
- queryFlag :: QueryParam param => Text -> param
- formToQuery :: (QueryParam param, Monoid param, ToForm f) => f -> param
- class QueryParam param where
  - queryParam :: ToHttpApiData a => Text -> Maybe a -> param
  - queryParamToList :: param -> [(Text, Maybe Text)]
- header :: forall (scheme :: Scheme). ByteString -> ByteString -> Option scheme
- attachHeader :: ByteString -> ByteString -> Request -> Request
- headerRedacted :: forall (scheme :: Scheme). ByteString -> ByteString -> Option scheme
- cookieJar :: forall (scheme :: Scheme). CookieJar -> Option scheme
- basicAuth :: ByteString -> ByteString -> Option 'Https
- basicAuthUnsafe :: forall (scheme :: Scheme). ByteString -> ByteString -> Option scheme
- basicProxyAuth :: forall (scheme :: Scheme). ByteString -> ByteString -> Option scheme
- oAuth1 :: forall (scheme :: Scheme). ByteString -> ByteString -> ByteString -> ByteString -> Option scheme
- oAuth2Bearer :: ByteString -> Option 'Https
- oAuth2Token :: ByteString -> Option 'Https
- customAuth :: forall (scheme :: Scheme). (Request -> IO Request) -> Option scheme
- port :: forall (scheme :: Scheme). Int -> Option scheme
- decompress :: forall (scheme :: Scheme). (ByteString -> Bool) -> Option scheme
- responseTimeout :: forall (scheme :: Scheme). Int -> Option scheme
- httpVersion :: forall (scheme :: Scheme). Int -> Int -> Option scheme
- data IgnoreResponse
- ignoreResponse :: Proxy IgnoreResponse
- data JsonResponse a
- jsonResponse :: Proxy (JsonResponse a)
- data BsResponse
- bsResponse :: Proxy BsResponse
- data LbsResponse
- lbsResponse :: Proxy LbsResponse
- responseBody :: HttpResponse response => response -> HttpResponseBody response
- responseStatusCode :: HttpResponse response => response -> Int
- responseStatusMessage :: HttpResponse response => response -> ByteString
- responseHeader :: HttpResponse response => response -> ByteString -> Maybe ByteString
- responseCookieJar :: HttpResponse response => response -> CookieJar
- class HttpResponse response where
  - type HttpResponseBody response
  - toVanillaResponse :: response -> Response (HttpResponseBody response)
  - getHttpResponse :: Response BodyReader -> IO response
  - acceptHeader :: Proxy response -> Maybe ByteString
- data HttpException
  - = VanillaHttpException HttpException
  - | JsonHttpException String
- isStatusCodeException :: HttpException -> Maybe (Response ())
- data CanHaveBody
  - = CanHaveBody
  - | NoBody
- data Scheme
  - = Http
  - | Https

# Making a request

To make an HTTP request you normally need only one function: `req`.

req Source #

Arguments

:: forall m method body response (scheme :: Scheme). (MonadHttp m, HttpMethod method, HttpBody body, HttpResponse response, HttpBodyAllowed (AllowsBody method) (ProvidesBody body)) |
=> method | HTTP method
-> Url scheme | `Url`—location of resource
-> body | Body of the request
-> Proxy response | A hint how to interpret response
-> Option scheme | Collection of optional parameters
-> m response | Response

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:

- `ignoreResponse`
- `jsonResponse`
- `bsResponse` (to get a strict `ByteString`)
- `lbsResponse` (to get a lazy `ByteString`)

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

Expand

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)

reqBr Source #

Arguments

:: forall m method body (scheme :: Scheme) a. (MonadHttp m, HttpMethod method, HttpBody body, HttpBodyAllowed (AllowsBody method) (ProvidesBody body)) |
=> method | HTTP method
-> Url scheme | `Url`—location of resource
-> body | Body of the request
-> Option scheme | Collection of optional parameters
-> (Response BodyReader -> IO a) | How to consume response
-> m a | Result

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.

Since: 1.0.0

reqCb Source #

Arguments

:: forall m method body response (scheme :: Scheme). (MonadHttp m, HttpMethod method, HttpBody body, HttpResponse response, HttpBodyAllowed (AllowsBody method) (ProvidesBody body)) |
=> method | HTTP method
-> Url scheme | `Url`—location of resource
-> body | Body of the request
-> Proxy response | A hint how to interpret response
-> Option scheme | Collection of optional parameters
-> (Request -> m Request) | Callback to modify the request
-> m response | Response

A version of `req` that takes a callback to modify the `Request`, but otherwise performs the request identically.

Since: 3.7.0

req' Source #

Arguments

:: forall m method body (scheme :: Scheme) a. (MonadHttp m, HttpMethod method, HttpBody body, HttpBodyAllowed (AllowsBody method) (ProvidesBody body)) |
=> method | HTTP method
-> Url scheme | `Url`—location of resource
-> body | Body of the request
-> Option scheme | Collection of optional parameters
-> (Request -> Manager -> m a) | How to perform request
-> m a | Result

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.

Since: 0.3.0

withReqManager :: MonadIO m => (Manager -> m a) -> m a Source #

Perform an action using the global implicit `Manager` that the rest of the library uses. This allows to reuse connections that the `Manager` controls.

# Embedding requests in your monad

To use `req` in your monad, all you need to do is to make the monad an instance of the `MonadHttp` type class.

When writing a library, keep your API polymorphic in terms of `MonadHttp`, only define instance of `MonadHttp` in final application. Another option is to use a `newtype`-wrapped monad stack and define `MonadHttp` for it. As of the version 0.4.0, the `Req` monad that follows this strategy is provided out-of-the-box (see below).

class MonadIO m => MonadHttp (m :: Type -> Type) where Source #

A type class for monads that support performing HTTP requests. Typically, you only need to define the `handleHttpException` method unless you want to tweak `HttpConfig`.

Minimal complete definition

handleHttpException

Methods

handleHttpException :: HttpException -> m a Source #

This method describes how to deal with `HttpException` that was caught by the library. One option is to re-throw it if you are OK with exceptions, but if you prefer working with something like `MonadError`, this is the right place to pass it to `throwError`.

getHttpConfig :: m HttpConfig Source #

Return the `HttpConfig` to be used when performing HTTP requests. Default implementation returns its `def` value, which is described in the documentation for the type. Common usage pattern with manually defined `getHttpConfig` is to return some hard-coded value, or a value extracted from `MonadReader` if a more flexible approach to configuration is desirable.

#### Instances

Instances details

MonadHttp Req Source # |
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> Req a Source # getHttpConfig :: Req HttpConfig Source #
MonadHttp m => MonadHttp (MaybeT m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> MaybeT m a Source # getHttpConfig :: MaybeT m HttpConfig Source #
(MonadHttp m, Monoid w) => MonadHttp (AccumT w m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> AccumT w m a Source # getHttpConfig :: AccumT w m HttpConfig Source #
MonadHttp m => MonadHttp (ExceptT e m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> ExceptT e m a Source # getHttpConfig :: ExceptT e m HttpConfig Source #
MonadHttp m => MonadHttp (IdentityT m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> IdentityT m a Source # getHttpConfig :: IdentityT m HttpConfig Source #
MonadHttp m => MonadHttp (ReaderT r m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> ReaderT r m a Source # getHttpConfig :: ReaderT r m HttpConfig Source #
MonadHttp m => MonadHttp (SelectT r m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> SelectT r m a Source # getHttpConfig :: SelectT r m HttpConfig Source #
MonadHttp m => MonadHttp (StateT s m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> StateT s m a Source # getHttpConfig :: StateT s m HttpConfig Source #
MonadHttp m => MonadHttp (StateT s m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> StateT s m a Source # getHttpConfig :: StateT s m HttpConfig Source #
(MonadHttp m, Monoid w) => MonadHttp (WriterT w m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> WriterT w m a Source # getHttpConfig :: WriterT w m HttpConfig Source #
(MonadHttp m, Monoid w) => MonadHttp (WriterT w m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> WriterT w m a Source # getHttpConfig :: WriterT w m HttpConfig Source #
(MonadHttp m, Monoid w) => MonadHttp (WriterT w m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> WriterT w m a Source # getHttpConfig :: WriterT w m HttpConfig Source #
MonadHttp m => MonadHttp (ContT r m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> ContT r m a Source # getHttpConfig :: ContT r m HttpConfig Source #
(MonadHttp m, Monoid w) => MonadHttp (RWST r w s m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> RWST r w s m a Source # getHttpConfig :: RWST r w s m HttpConfig Source #
(MonadHttp m, Monoid w) => MonadHttp (RWST r w s m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> RWST r w s m a Source # getHttpConfig :: RWST r w s m HttpConfig Source #
(MonadHttp m, Monoid w) => MonadHttp (RWST r w s m) Source # | Since: 3.10.0
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> RWST r w s m a Source # getHttpConfig :: RWST r w s m HttpConfig Source #

data HttpConfig Source #

`HttpConfig` contains settings to be used when making HTTP requests.

Constructors

HttpConfig |

Fields

- httpConfigProxy :: Maybe Proxy

  Proxy to use. By default values of `HTTP_PROXY` and `HTTPS_PROXY` environment variables are respected, this setting overwrites them. Default value: `Nothing`.

- httpConfigRedirectCount :: Int

  How many redirects to follow when getting a resource. Default value: 10.

- httpConfigAltManager :: Maybe Manager

  Alternative `Manager` to use. `Nothing` (default value) means that the default implicit manager will be used (that's what you want in 99% of cases).

- httpConfigCheckResponse :: forall b. Request -> Response b -> ByteString -> Maybe HttpExceptionContent

  Function to check the response immediately after receiving the status and headers, before streaming of response body. The third argument is the beginning of response body (typically first 1024 bytes). This is used for throwing exceptions on non-success status codes by default (set to `\_ _ _ -> Nothing` if this behavior is not desirable).

  When the value this function returns is `Nothing`, nothing will happen. When it there is `HttpExceptionContent` inside `Just`, it will be thrown.

  Throwing is better then just returning a request with non-2xx status code because in that case something is wrong and we need a way to short-cut execution (also remember that Req retries automatically on request timeouts and such, so when your request fails, it's certainly something exceptional). The thrown exception is caught by the library though and is available in `handleHttpException`.

  Note: signature of this function was changed in the version 1.0.0.

  Since: 0.3.0

- httpConfigRetryPolicy :: RetryPolicyM IO

  The retry policy to use for request retrying. By default `def` is used (see `RetryPolicyM`).

  Note: signature of this function was changed to disallow `IO` in version 1.0.0 and then changed back to its current form in 3.1.0.

  Since: 0.3.0

- httpConfigRetryJudge :: forall b. RetryStatus -> Response b -> Bool

  The function is used to decide whether to retry a request. `True` means that the request should be retried.

  Note: signature of this function was changed in the version 1.0.0.

  Since: 0.3.0

- httpConfigRetryJudgeException :: RetryStatus -> SomeException -> Bool

  Similar to `httpConfigRetryJudge`, but is used to decide when to retry requests that resulted in an exception. By default it retries on response timeout and connection timeout (changed in version 3.8.0).

  Since: 3.4.0

- httpConfigBodyPreviewLength :: forall a. Num a => a

  Max length of preview fragment of response body.

  Since: 3.6.0

defaultHttpConfig :: HttpConfig Source #

The default value of `HttpConfig`.

Since: 2.0.0

data Req a Source #

A monad that allows us to run `req` in any `IO`-enabled monad without having to define new instances.

Since: 0.4.0

#### Instances

Instances details

MonadIO Req Source # |
Instance details Defined in Network.HTTP.Req Methods liftIO :: IO a -> Req a Source #
MonadCatch Req Source # | Since: 3.7.0
Instance details Defined in Network.HTTP.Req Methods catch :: (HasCallStack, Exception e) => Req a -> (e -> Req a) -> Req a Source #
MonadMask Req Source # | Since: 3.7.0
Instance details Defined in Network.HTTP.Req Methods mask :: HasCallStack => ((forall a. Req a -> Req a) -> Req b) -> Req b Source # uninterruptibleMask :: HasCallStack => ((forall a. Req a -> Req a) -> Req b) -> Req b Source # generalBracket :: HasCallStack => Req a -> (a -> ExitCase b -> Req c) -> (a -> Req b) -> Req (b, c) Source #
MonadThrow Req Source # | Since: 3.7.0
Instance details Defined in Network.HTTP.Req Methods throwM :: (HasCallStack, Exception e) => e -> Req a Source #
Applicative Req Source # |
Instance details Defined in Network.HTTP.Req Methods pure :: a -> Req a Source # (<*>) :: Req (a -> b) -> Req a -> Req b Source # liftA2 :: (a -> b -> c) -> Req a -> Req b -> Req c Source # (*>) :: Req a -> Req b -> Req b Source # (<*) :: Req a -> Req b -> Req a Source #
Functor Req Source # |
Instance details Defined in Network.HTTP.Req Methods fmap :: (a -> b) -> Req a -> Req b Source # (<$) :: a -> Req b -> Req a Source #
Monad Req Source # |
Instance details Defined in Network.HTTP.Req Methods (>>=) :: Req a -> (a -> Req b) -> Req b Source # (>>) :: Req a -> Req b -> Req b Source # return :: a -> Req a Source #
MonadHttp Req Source # |
Instance details Defined in Network.HTTP.Req Methods handleHttpException :: HttpException -> Req a Source # getHttpConfig :: Req HttpConfig Source #
MonadUnliftIO Req Source # |
Instance details Defined in Network.HTTP.Req Methods withRunInIO :: ((forall a. Req a -> IO a) -> IO b) -> Req b Source #
MonadBaseControl IO Req Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type StM Req a |
Instance details Defined in Network.HTTP.Req type StM Req a = a

Methods

liftBaseWith :: (RunInBase Req IO -> IO a) -> Req a Source #

restoreM :: StM Req a -> Req a Source #

MonadBase IO Req Source # |
Instance details Defined in Network.HTTP.Req Methods liftBase :: IO α -> Req α Source #
type StM Req a Source # |
Instance details Defined in Network.HTTP.Req type StM Req a = a

runReq Source #

Arguments

:: MonadIO m |
=> HttpConfig | `HttpConfig` to use
-> Req a | Computation to run
-> m a |

Run a computation in the `Req` monad with the given `HttpConfig`. In the case of an exceptional situation an `HttpException` will be thrown.

Since: 0.4.0

# Request

## Method

The package supports all methods as defined by RFC 2616, and `PATCH` which is defined by RFC 5789—that should be enough to talk to RESTful APIs. In some cases, however, you may want to add more methods (e.g. you work with WebDAV https://en.wikipedia.org/wiki/WebDAV); no need to compromise on type safety and hack, it only takes a couple of seconds to define a new method that will works seamlessly, see `HttpMethod`.

data GET Source #

`GET` method.

Constructors

GET |

#### Instances

Instances details

HttpMethod GET Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody GET |
Instance details Defined in Network.HTTP.Req type AllowsBody GET = 'NoBody

Methods

httpMethodName :: Proxy GET -> ByteString Source #

type AllowsBody GET Source # |
Instance details Defined in Network.HTTP.Req type AllowsBody GET = 'NoBody

data POST Source #

`POST` method.

Constructors

POST |

#### Instances

Instances details

HttpMethod POST Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody POST |
Instance details Defined in Network.HTTP.Req type AllowsBody POST = 'CanHaveBody

Methods

httpMethodName :: Proxy POST -> ByteString Source #

type AllowsBody POST Source # |
Instance details Defined in Network.HTTP.Req type AllowsBody POST = 'CanHaveBody

data HEAD Source #

`HEAD` method.

Constructors

HEAD |

#### Instances

Instances details

HttpMethod HEAD Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody HEAD |
Instance details Defined in Network.HTTP.Req type AllowsBody HEAD = 'NoBody

Methods

httpMethodName :: Proxy HEAD -> ByteString Source #

type AllowsBody HEAD Source # |
Instance details Defined in Network.HTTP.Req type AllowsBody HEAD = 'NoBody

data PUT Source #

`PUT` method.

Constructors

PUT |

#### Instances

Instances details

HttpMethod PUT Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody PUT |
Instance details Defined in Network.HTTP.Req type AllowsBody PUT = 'CanHaveBody

Methods

httpMethodName :: Proxy PUT -> ByteString Source #

type AllowsBody PUT Source # |
Instance details Defined in Network.HTTP.Req type AllowsBody PUT = 'CanHaveBody

data DELETE Source #

`DELETE` method. RFC 7231 allows a payload in DELETE but without semantics.

Note: before version 3.4.0 this method did not allow request bodies.

Constructors

DELETE |

#### Instances

Instances details

HttpMethod DELETE Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody DELETE |
Instance details Defined in Network.HTTP.Req type AllowsBody DELETE = 'CanHaveBody

Methods

httpMethodName :: Proxy DELETE -> ByteString Source #

type AllowsBody DELETE Source # |
Instance details Defined in Network.HTTP.Req type AllowsBody DELETE = 'CanHaveBody

data TRACE Source #

`TRACE` method.

Constructors

TRACE |

#### Instances

Instances details

HttpMethod TRACE Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody TRACE |
Instance details Defined in Network.HTTP.Req type AllowsBody TRACE = 'CanHaveBody

Methods

httpMethodName :: Proxy TRACE -> ByteString Source #

type AllowsBody TRACE Source # |
Instance details Defined in Network.HTTP.Req type AllowsBody TRACE = 'CanHaveBody

data CONNECT Source #

`CONNECT` method.

Constructors

CONNECT |

#### Instances

Instances details

HttpMethod CONNECT Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody CONNECT |
Instance details Defined in Network.HTTP.Req type AllowsBody CONNECT = 'CanHaveBody

Methods

httpMethodName :: Proxy CONNECT -> ByteString Source #

type AllowsBody CONNECT Source # |
Instance details Defined in Network.HTTP.Req type AllowsBody CONNECT = 'CanHaveBody

data OPTIONS Source #

`OPTIONS` method.

Constructors

OPTIONS |

#### Instances

Instances details

HttpMethod OPTIONS Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody OPTIONS |
Instance details Defined in Network.HTTP.Req type AllowsBody OPTIONS = 'NoBody

Methods

httpMethodName :: Proxy OPTIONS -> ByteString Source #

type AllowsBody OPTIONS Source # |
Instance details Defined in Network.HTTP.Req type AllowsBody OPTIONS = 'NoBody

data PATCH Source #

`PATCH` method.

Constructors

PATCH |

#### Instances

Instances details

HttpMethod PATCH Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody PATCH |
Instance details Defined in Network.HTTP.Req type AllowsBody PATCH = 'CanHaveBody

Methods

httpMethodName :: Proxy PATCH -> ByteString Source #

type AllowsBody PATCH Source # |
Instance details Defined in Network.HTTP.Req type AllowsBody PATCH = 'CanHaveBody

class HttpMethod (a :: k) where Source #

A type class for types that can be used as an HTTP method. To define a non-standard method, follow this example that defines `COPY`:

    data COPY = COPY

    instance HttpMethod COPY where
      type AllowsBody COPY = 'CanHaveBody
      httpMethodName Proxy = "COPY"

Associated Types

type AllowsBody (a :: k) :: CanHaveBody Source #

Type function `AllowsBody` returns a type of kind `CanHaveBody` which tells the rest of the library whether the method can have body or not. We use the special type `CanHaveBody` lifted to the kind level instead of `Bool` to get more user-friendly compiler messages.

Methods

httpMethodName :: Proxy a -> ByteString Source #

Return name of the method as a `ByteString`.

#### Instances

Instances details

HttpMethod CONNECT Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody CONNECT |
Instance details Defined in Network.HTTP.Req type AllowsBody CONNECT = 'CanHaveBody

Methods

httpMethodName :: Proxy CONNECT -> ByteString Source #

HttpMethod DELETE Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody DELETE |
Instance details Defined in Network.HTTP.Req type AllowsBody DELETE = 'CanHaveBody

Methods

httpMethodName :: Proxy DELETE -> ByteString Source #

HttpMethod GET Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody GET |
Instance details Defined in Network.HTTP.Req type AllowsBody GET = 'NoBody

Methods

httpMethodName :: Proxy GET -> ByteString Source #

HttpMethod HEAD Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody HEAD |
Instance details Defined in Network.HTTP.Req type AllowsBody HEAD = 'NoBody

Methods

httpMethodName :: Proxy HEAD -> ByteString Source #

HttpMethod OPTIONS Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody OPTIONS |
Instance details Defined in Network.HTTP.Req type AllowsBody OPTIONS = 'NoBody

Methods

httpMethodName :: Proxy OPTIONS -> ByteString Source #

HttpMethod PATCH Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody PATCH |
Instance details Defined in Network.HTTP.Req type AllowsBody PATCH = 'CanHaveBody

Methods

httpMethodName :: Proxy PATCH -> ByteString Source #

HttpMethod POST Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody POST |
Instance details Defined in Network.HTTP.Req type AllowsBody POST = 'CanHaveBody

Methods

httpMethodName :: Proxy POST -> ByteString Source #

HttpMethod PUT Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody PUT |
Instance details Defined in Network.HTTP.Req type AllowsBody PUT = 'CanHaveBody

Methods

httpMethodName :: Proxy PUT -> ByteString Source #

HttpMethod TRACE Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type AllowsBody TRACE |
Instance details Defined in Network.HTTP.Req type AllowsBody TRACE = 'CanHaveBody

Methods

httpMethodName :: Proxy TRACE -> ByteString Source #

## URL

We use `Url`s which are correct by construction, see `Url`. To build a `Url` from a `URI`, use `useHttpURI`, `useHttpsURI`, or generic `useURI`.

data Url (scheme :: Scheme) Source #

Request's `Url`. Start constructing your `Url` with `http` or `https` specifying the scheme and host at the same time. Then use the `(`/~`)` and `(`/:`)` operators to grow the path one piece at a time. Every single piece of path will be url(percent)-encoded, so using `(`/~`)` and `(`/:`)` is the only way to have forward slashes between path segments. This approach makes working with dynamic path segments easy and safe. See examples below how to represent various `Url`s (make sure the `OverloadedStrings` language extension is enabled).

#### Examples

Expand

    http "httpbin.org"
    -- http://httpbin.org

    https "httpbin.org"
    -- https://httpbin.org

    https "httpbin.org" /: "encoding" /: "utf8"
    -- https://httpbin.org/encoding/utf8

    https "httpbin.org" /: "foo" /: "bar/baz"
    -- https://httpbin.org/foo/bar%2Fbaz

    https "httpbin.org" /: "bytes" /~ (10 :: Int)
    -- https://httpbin.org/bytes/10

    https "юникод.рф"
    -- https://%D1%8E%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4.%D1%80%D1%84

#### Instances

Instances details

Typeable scheme => Lift (Url scheme :: Type) Source # |
Instance details Defined in Network.HTTP.Req Methods lift :: Quote m => Url scheme -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => Url scheme -> Code m (Url scheme) Source #
Typeable scheme => Data (Url scheme) Source # |

Instance details

Defined in Network.HTTP.Req

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Url scheme -> c (Url scheme) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Url scheme) Source #

toConstr :: Url scheme -> Constr Source #

dataTypeOf :: Url scheme -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Url scheme)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Url scheme)) Source #

gmapT :: (forall b. Data b => b -> b) -> Url scheme -> Url scheme Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Url scheme -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Url scheme -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Url scheme -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Url scheme -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Url scheme -> m (Url scheme) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Url scheme -> m (Url scheme) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Url scheme -> m (Url scheme) Source #

Generic (Url scheme) Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type Rep (Url scheme) |

Instance details

Defined in Network.HTTP.Req

type Rep (Url scheme) = D1 ('MetaData "Url" "Network.HTTP.Req" "req-3.13.4-1ZBL5mTVSOW64mQjyFszs4" 'False) (C1 ('MetaCons "Url" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Scheme) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (NonEmpty Text))))

Methods

from :: Url scheme -> Rep (Url scheme) x Source #

to :: Rep (Url scheme) x -> Url scheme Source #

Show (Url scheme) Source # |
Instance details Defined in Network.HTTP.Req Methods showsPrec :: Int -> Url scheme -> ShowS Source # show :: Url scheme -> String Source # showList :: [Url scheme] -> ShowS Source #
Eq (Url scheme) Source # |
Instance details Defined in Network.HTTP.Req Methods (==) :: Url scheme -> Url scheme -> Bool Source # (/=) :: Url scheme -> Url scheme -> Bool Source #
Ord (Url scheme) Source # |

Instance details

Defined in Network.HTTP.Req

Methods

compare :: Url scheme -> Url scheme -> Ordering Source #

(<) :: Url scheme -> Url scheme -> Bool Source #

(<=) :: Url scheme -> Url scheme -> Bool Source #

(>) :: Url scheme -> Url scheme -> Bool Source #

(>=) :: Url scheme -> Url scheme -> Bool Source #

max :: Url scheme -> Url scheme -> Url scheme Source #

min :: Url scheme -> Url scheme -> Url scheme Source #

type Rep (Url scheme) Source # |

Instance details

Defined in Network.HTTP.Req

type Rep (Url scheme) = D1 ('MetaData "Url" "Network.HTTP.Req" "req-3.13.4-1ZBL5mTVSOW64mQjyFszs4" 'False) (C1 ('MetaCons "Url" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Scheme) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (NonEmpty Text))))

http :: Text -> Url 'Http Source #

Given host name, produce a `Url` which has “http” as its scheme and empty path. This also sets port to `80`.

https :: Text -> Url 'Https Source #

Given host name, produce a `Url` which has “https” as its scheme and empty path. This also sets port to `443`.

(/~) :: forall a (scheme :: Scheme). ToHttpApiData a => Url scheme -> a -> Url scheme infixl 5 Source #

Grow a given `Url` appending a single path segment to it. Note that the path segment can be of any type that is an instance of `ToHttpApiData`.

(/:) :: forall (scheme :: Scheme). Url scheme -> Text -> Url scheme infixl 5 Source #

A type-constrained version of `(`/~`)` to remove ambiguity in the cases when next URL piece is a `Text` literal.

useHttpURI :: forall (scheme :: Scheme). URI -> Maybe (Url 'Http, Option scheme) Source #

The `useHttpURI` function provides an alternative method to get `Url` (possibly with some `Option`s) from a `URI`. This is useful when you are given a URL to query dynamically and don't know it beforehand.

This function expects the scheme to be “http” and host to be present.

Since: 3.0.0

useHttpsURI :: forall (scheme :: Scheme). URI -> Maybe (Url 'Https, Option scheme) Source #

Just like `useHttpURI`, but expects the “https” scheme.

Since: 3.0.0

useURI :: forall (scheme0 :: Scheme) (scheme1 :: Scheme). URI -> Maybe (Either (Url 'Http, Option scheme0) (Url 'Https, Option scheme1)) Source #

A combination of `useHttpURI` and `useHttpsURI` for cases when scheme is not known in advance.

Since: 3.0.0

urlQ :: QuasiQuoter Source #

A quasiquoter to build an `Url` and `Option` tuple. The type of the generated expression is `(`Url` scheme0, `Option` scheme1)` with `scheme0` being either `Http` or `Https` depending on the input.

Since: 3.2.0

renderUrl :: forall (scheme :: Scheme). Url scheme -> Text Source #

Render a `Url` as `Text`.

Since: 3.4.0

## Body

A number of options for request bodies are available. The `Content-Type` header is set for you automatically according to the body option you use (it's always specified in the documentation for a given body option). To add your own way to represent request body, define an instance of `HttpBody`.

data NoReqBody Source #

This data type represents empty body of an HTTP request. This is the data type to use with `HttpMethod`s that cannot have a body, as it's the only type for which `ProvidesBody` returns `NoBody`.

Using of this body option does not set the `Content-Type` header.

Constructors

NoReqBody |

#### Instances

Instances details

HttpBody NoReqBody Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: NoReqBody -> RequestBody Source # getRequestContentType :: NoReqBody -> Maybe ByteString Source #

newtype ReqBodyJson a Source #

This body option allows us to use a JSON object as the request body—probably the most popular format right now. Just wrap a data type that is an instance of `ToJSON` type class and you are done: it will be converted to JSON and inserted as request body.

This body option sets the `Content-Type` header to `"application/json; charset=utf-8"` value.

Constructors

ReqBodyJson a |

#### Instances

Instances details

ToJSON a => HttpBody (ReqBodyJson a) Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyJson a -> RequestBody Source # getRequestContentType :: ReqBodyJson a -> Maybe ByteString Source #

newtype ReqBodyFile Source #

This body option streams request body from a file. It is expected that the file size does not change during streaming.

Using of this body option does not set the `Content-Type` header.

Constructors

ReqBodyFile FilePath |

#### Instances

Instances details

HttpBody ReqBodyFile Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyFile -> RequestBody Source # getRequestContentType :: ReqBodyFile -> Maybe ByteString Source #

newtype ReqBodyBs Source #

HTTP request body represented by a strict `ByteString`.

Using of this body option does not set the `Content-Type` header.

Constructors

ReqBodyBs ByteString |

#### Instances

Instances details

HttpBody ReqBodyBs Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyBs -> RequestBody Source # getRequestContentType :: ReqBodyBs -> Maybe ByteString Source #

newtype ReqBodyLbs Source #

HTTP request body represented by a lazy `ByteString`.

Using of this body option does not set the `Content-Type` header.

Constructors

ReqBodyLbs ByteString |

#### Instances

Instances details

HttpBody ReqBodyLbs Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyLbs -> RequestBody Source # getRequestContentType :: ReqBodyLbs -> Maybe ByteString Source #

newtype ReqBodyUrlEnc Source #

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.

Constructors

ReqBodyUrlEnc FormUrlEncodedParam |

#### Instances

Instances details

HttpBody ReqBodyUrlEnc Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyUrlEnc -> RequestBody Source # getRequestContentType :: ReqBodyUrlEnc -> Maybe ByteString Source #

data FormUrlEncodedParam Source #

An opaque monoidal value that allows to collect URL-encoded parameters to be wrapped in `ReqBodyUrlEnc`.

#### Instances

Instances details

Monoid FormUrlEncodedParam Source # |
Instance details Defined in Network.HTTP.Req Methods mempty :: FormUrlEncodedParam Source # mappend :: FormUrlEncodedParam -> FormUrlEncodedParam -> FormUrlEncodedParam Source # mconcat :: [FormUrlEncodedParam] -> FormUrlEncodedParam Source #
Semigroup FormUrlEncodedParam Source # |
Instance details Defined in Network.HTTP.Req Methods (<>) :: FormUrlEncodedParam -> FormUrlEncodedParam -> FormUrlEncodedParam Source # sconcat :: NonEmpty FormUrlEncodedParam -> FormUrlEncodedParam Source # stimes :: Integral b => b -> FormUrlEncodedParam -> FormUrlEncodedParam Source #
FromForm FormUrlEncodedParam Source # | Use `formToQuery`. Since: 3.11.0
Instance details Defined in Network.HTTP.Req Methods fromForm :: Form -> Either Text FormUrlEncodedParam Source #
QueryParam FormUrlEncodedParam Source # |
Instance details Defined in Network.HTTP.Req Methods queryParam :: ToHttpApiData a => Text -> Maybe a -> FormUrlEncodedParam Source # queryParamToList :: FormUrlEncodedParam -> [(Text, Maybe Text)] Source #

data ReqBodyMultipart Source #

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

Expand

    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)

Since: 0.2.0

#### Instances

Instances details

HttpBody ReqBodyMultipart Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyMultipart -> RequestBody Source # getRequestContentType :: ReqBodyMultipart -> Maybe ByteString Source #

reqBodyMultipart :: MonadIO m => [Part] -> m ReqBodyMultipart Source #

Create `ReqBodyMultipart` request body from a collection of `Part`s.

Since: 0.2.0

class HttpBody body where Source #

A type class for things that can be interpreted as an HTTP `RequestBody`.

Minimal complete definition

getRequestBody

Methods

getRequestBody :: body -> RequestBody Source #

How to get actual `RequestBody`.

getRequestContentType :: body -> Maybe ByteString Source #

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.

#### Instances

Instances details

HttpBody NoReqBody Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: NoReqBody -> RequestBody Source # getRequestContentType :: NoReqBody -> Maybe ByteString Source #
HttpBody ReqBodyBs Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyBs -> RequestBody Source # getRequestContentType :: ReqBodyBs -> Maybe ByteString Source #
HttpBody ReqBodyFile Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyFile -> RequestBody Source # getRequestContentType :: ReqBodyFile -> Maybe ByteString Source #
HttpBody ReqBodyLbs Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyLbs -> RequestBody Source # getRequestContentType :: ReqBodyLbs -> Maybe ByteString Source #
HttpBody ReqBodyMultipart Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyMultipart -> RequestBody Source # getRequestContentType :: ReqBodyMultipart -> Maybe ByteString Source #
HttpBody ReqBodyUrlEnc Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyUrlEnc -> RequestBody Source # getRequestContentType :: ReqBodyUrlEnc -> Maybe ByteString Source #
ToJSON a => HttpBody (ReqBodyJson a) Source # |
Instance details Defined in Network.HTTP.Req Methods getRequestBody :: ReqBodyJson a -> RequestBody Source # getRequestContentType :: ReqBodyJson a -> Maybe ByteString Source #

type family ProvidesBody body :: CanHaveBody where ... Source #

The type function recognizes `NoReqBody` as having `NoBody`, while any other body option `CanHaveBody`. This forces the user to use `NoReqBody` with `GET` method and other methods that should not have body.

Equations

ProvidesBody NoReqBody = 'NoBody |
ProvidesBody body = 'CanHaveBody |

type family HttpBodyAllowed (allowsBody :: CanHaveBody) (providesBody :: CanHaveBody) where ... Source #

This type function allows any HTTP body if method says it `CanHaveBody`. When the method says it should have `NoBody`, the only body option to use is `NoReqBody`.

Equations

HttpBodyAllowed 'NoBody 'NoBody = () |
HttpBodyAllowed 'CanHaveBody body = () |
HttpBodyAllowed 'NoBody 'CanHaveBody = TypeError ('Text "This HTTP method does not allow attaching a request body.") :: Constraint |

## Optional parameters

Optional parameters of request include things like query parameters, headers, port number, etc. All optional parameters have the type `Option`, which is a `Monoid`. This means that you can use `mempty` as the last argument of `req` to specify no optional parameters, or combine `Option`s using `mappend` or `(`<>`)` to have several of them at once.

data Option (scheme :: Scheme) Source #

The opaque `Option` type is a `Monoid` you can use to pack collection of optional parameters like query parameters and headers. See sections below to learn which `Option` primitives are available.

#### Instances

Instances details

Monoid (Option scheme) Source # |
Instance details Defined in Network.HTTP.Req Methods mempty :: Option scheme Source # mappend :: Option scheme -> Option scheme -> Option scheme Source # mconcat :: [Option scheme] -> Option scheme Source #
Semigroup (Option scheme) Source # |
Instance details Defined in Network.HTTP.Req Methods (<>) :: Option scheme -> Option scheme -> Option scheme Source # sconcat :: NonEmpty (Option scheme) -> Option scheme Source # stimes :: Integral b => b -> Option scheme -> Option scheme Source #
FromForm (Option scheme) Source # | Use `formToQuery`. Since: 3.11.0
Instance details Defined in Network.HTTP.Req Methods fromForm :: Form -> Either Text (Option scheme) Source #
QueryParam (Option scheme) Source # |
Instance details Defined in Network.HTTP.Req Methods queryParam :: ToHttpApiData a => Text -> Maybe a -> Option scheme Source # queryParamToList :: Option scheme -> [(Text, Maybe Text)] Source #

### Query parameters

This section describes a polymorphic interface that can be used to construct query parameters (of the type `Option`) and form URL-encoded bodies (of the type `FormUrlEncodedParam`).

(=:) :: (QueryParam param, ToHttpApiData a) => Text -> a -> param infix 7 Source #

This operator builds a query parameter that will be included in URL of your request after the question sign `?`. This is the same syntax you use with form URL encoded request bodies.

This operator is defined in terms of `queryParam`:

    name =: value = queryParam name (pure value)

queryFlag :: QueryParam param => Text -> param Source #

Construct a flag, that is, a valueless query parameter. For example, in the following URL `"a"` is a flag, while `"b"` is a query parameter with a value:

    https://httpbin.org/foo/bar?a&b=10

This operator is defined in terms of `queryParam`:

    queryFlag name = queryParam name (Nothing :: Maybe ())

formToQuery :: (QueryParam param, Monoid param, ToForm f) => f -> param Source #

Construct query parameters from a `ToForm` instance. This function produces the same query params as `urlEncodeAsFormStable`.

Note that `Form` doesn't have the concept of parameters with the empty value (i.e. what you can get by `key =: ""`). If the value is empty, it will be encoded as a valueless parameter (i.e. what you can get by `queryFlag key`).

Since: 3.11.0

class QueryParam param where Source #

A type class for query-parameter-like things. The reason to have an overloaded `queryParam` is to be able to use it as an `Option` and as a `FormUrlEncodedParam` when constructing form URL encoded request bodies. Having the same syntax for these cases seems natural and user-friendly.

Methods

queryParam :: ToHttpApiData a => Text -> Maybe a -> param Source #

Create a query parameter with given name and value. If value is `Nothing`, it won't be included at all (i.e. you create a flag this way). It's recommended to use `(`=:`)` and `queryFlag` instead of this method, because they are easier to read.

queryParamToList :: param -> [(Text, Maybe Text)] Source #

Get the query parameter names and values set by `queryParam`.

Since: 3.11.0

#### Instances

Instances details

QueryParam FormUrlEncodedParam Source # |
Instance details Defined in Network.HTTP.Req Methods queryParam :: ToHttpApiData a => Text -> Maybe a -> FormUrlEncodedParam Source # queryParamToList :: FormUrlEncodedParam -> [(Text, Maybe Text)] Source #
QueryParam (Option scheme) Source # |
Instance details Defined in Network.HTTP.Req Methods queryParam :: ToHttpApiData a => Text -> Maybe a -> Option scheme Source # queryParamToList :: Option scheme -> [(Text, Maybe Text)] Source #

### Headers

header Source #

Arguments

:: forall (scheme :: Scheme). ByteString | Header name
-> ByteString | Header value
-> Option scheme |

Create an `Option` that adds a header. Note that if you `mappend` two headers with the same names the leftmost header will win. This means, in particular, that you cannot create a request with several headers of the same name.

attachHeader :: ByteString -> ByteString -> Request -> Request Source #

Attach a header with given name and content to a `Request`.

Since: 1.1.0

headerRedacted :: forall (scheme :: Scheme). ByteString -> ByteString -> Option scheme Source #

Same as `header`, but with redacted values on print.

Since: 3.13.0

### Cookies

Support for cookies is quite minimalistic at the moment. It's possible to specify which cookies to send using `cookieJar` and inspect `Response` to extract `CookieJar` from it (see `responseCookieJar`).

cookieJar :: forall (scheme :: Scheme). CookieJar -> Option scheme Source #

Use the given `CookieJar`. A `CookieJar` can be obtained from a `Response` record.

### Authentication

This section provides the common authentication helpers in the form of `Option`s. You should always prefer the provided authentication `Option`s to manual construction of headers because it ensures that you only use one authentication method at a time (they overwrite each other) and provides additional type safety that prevents leaking of credentials in the cases when authentication relies on HTTPS for encrypting sensitive data.

basicAuth Source #

Arguments

:: ByteString | Username
-> ByteString | Password
-> Option 'Https | Auth `Option`

The `Option` adds basic authentication.

See also: https://en.wikipedia.org/wiki/Basic_access_authentication.

basicAuthUnsafe Source #

Arguments

:: forall (scheme :: Scheme). ByteString | Username
-> ByteString | Password
-> Option scheme | Auth `Option`

An alternative to `basicAuth` which works for any scheme. Note that using basic access authentication without SSL/TLS is vulnerable to attacks. Use `basicAuth` instead unless you know what you are doing.

Since: 0.3.1

basicProxyAuth Source #

Arguments

:: forall (scheme :: Scheme). ByteString | Username
-> ByteString | Password
-> Option scheme | Auth `Option`

The `Option` set basic proxy authentication header.

Since: 1.1.0

oAuth1 Source #

Arguments

:: forall (scheme :: Scheme). ByteString | Consumer token
-> ByteString | Consumer secret
-> ByteString | OAuth token
-> ByteString | OAuth token secret
-> Option scheme | Auth `Option`

The `Option` adds OAuth1 authentication.

Since: 0.2.0

oAuth2Bearer Source #

Arguments

:: ByteString | Token
-> Option 'Https | Auth `Option`

The `Option` adds an OAuth2 bearer token. This is treated by many services as the equivalent of a username and password.

The `Option` is defined as:

    oAuth2Bearer token = header "Authorization" ("Bearer " <> token)

See also: https://en.wikipedia.org/wiki/OAuth.

oAuth2Token Source #

Arguments

:: ByteString | Token
-> Option 'Https | Auth `Option`

The `Option` adds a not-quite-standard OAuth2 bearer token (that seems to be used only by GitHub). This will be treated by whatever services accept it as the equivalent of a username and password.

The `Option` is defined as:

    oAuth2Token token = header "Authorization" ("token" <> token)

See also: https://developer.github.com/v3/oauth#3-use-the-access-token-to-access-the-api.

customAuth :: forall (scheme :: Scheme). (Request -> IO Request) -> Option scheme Source #

A helper to create custom authentication `Option`s. The given `IO`-enabled request transformation is applied after all other modifications when constructing a request. Use wisely.

Since: 1.1.0

### Other

port :: forall (scheme :: Scheme). Int -> Option scheme Source #

Specify the port to connect to explicitly. Normally, `Url` you use determines the default port: `80` for HTTP and `443` for HTTPS. This `Option` allows us to choose an arbitrary port overwriting the defaults.

decompress Source #

Arguments

:: forall (scheme :: Scheme). (ByteString -> Bool) | Predicate that is given MIME type, it returns `True` when content should be decompressed on the fly.
-> Option scheme |

This `Option` controls whether gzipped data should be decompressed on the fly. By default everything except for `"application/x-tar"` is decompressed, i.e. we have:

    decompress (/= "application/x-tar")

You can also choose to decompress everything like this:

    decompress (const True)

responseTimeout Source #

Arguments

:: forall (scheme :: Scheme). Int | Number of microseconds to wait
-> Option scheme |

Specify the number of microseconds to wait for response. The default value is 30 seconds (defined in `ManagerSettings` of connection `Manager`).

httpVersion Source #

Arguments

:: forall (scheme :: Scheme). Int | Major version number
-> Int | Minor version number
-> Option scheme |

HTTP version to send to the server, the default is HTTP 1.1.

# Response

## Response interpretations

data IgnoreResponse Source #

Make a request and ignore the body of the response.

#### Instances

Instances details

Show IgnoreResponse Source # |
Instance details Defined in Network.HTTP.Req Methods showsPrec :: Int -> IgnoreResponse -> ShowS Source # show :: IgnoreResponse -> String Source # showList :: [IgnoreResponse] -> ShowS Source #
HttpResponse IgnoreResponse Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type HttpResponseBody IgnoreResponse |
Instance details Defined in Network.HTTP.Req type HttpResponseBody IgnoreResponse = ()

Methods

toVanillaResponse :: IgnoreResponse -> Response (HttpResponseBody IgnoreResponse) Source #

getHttpResponse :: Response BodyReader -> IO IgnoreResponse Source #

acceptHeader :: Proxy IgnoreResponse -> Maybe ByteString Source #

type HttpResponseBody IgnoreResponse Source # |
Instance details Defined in Network.HTTP.Req type HttpResponseBody IgnoreResponse = ()

ignoreResponse :: Proxy IgnoreResponse Source #

Use this as the fourth argument of `req` to specify that you want it to ignore the response body.

data JsonResponse a Source #

Make a request and interpret the body of the response as JSON. The `handleHttpException` method of `MonadHttp` instance corresponding to monad in which you use `req` will determine what to do in the case when parsing fails (the `JsonHttpException` constructor will be used).

#### Instances

Instances details

Show a => Show (JsonResponse a) Source # |
Instance details Defined in Network.HTTP.Req Methods showsPrec :: Int -> JsonResponse a -> ShowS Source # show :: JsonResponse a -> String Source # showList :: [JsonResponse a] -> ShowS Source #
FromJSON a => HttpResponse (JsonResponse a) Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type HttpResponseBody (JsonResponse a) |
Instance details Defined in Network.HTTP.Req type HttpResponseBody (JsonResponse a) = a

Methods

toVanillaResponse :: JsonResponse a -> Response (HttpResponseBody (JsonResponse a)) Source #

getHttpResponse :: Response BodyReader -> IO (JsonResponse a) Source #

acceptHeader :: Proxy (JsonResponse a) -> Maybe ByteString Source #

type HttpResponseBody (JsonResponse a) Source # |
Instance details Defined in Network.HTTP.Req type HttpResponseBody (JsonResponse a) = a

jsonResponse :: Proxy (JsonResponse a) Source #

Use this as the fourth argument of `req` to specify that you want it to return the `JsonResponse` interpretation.

data BsResponse Source #

Make a request and interpret the body of the response as a strict `ByteString`.

#### Instances

Instances details

Show BsResponse Source # |
Instance details Defined in Network.HTTP.Req Methods showsPrec :: Int -> BsResponse -> ShowS Source # show :: BsResponse -> String Source # showList :: [BsResponse] -> ShowS Source #
HttpResponse BsResponse Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type HttpResponseBody BsResponse |
Instance details Defined in Network.HTTP.Req type HttpResponseBody BsResponse = ByteString

Methods

toVanillaResponse :: BsResponse -> Response (HttpResponseBody BsResponse) Source #

getHttpResponse :: Response BodyReader -> IO BsResponse Source #

acceptHeader :: Proxy BsResponse -> Maybe ByteString Source #

type HttpResponseBody BsResponse Source # |
Instance details Defined in Network.HTTP.Req type HttpResponseBody BsResponse = ByteString

bsResponse :: Proxy BsResponse Source #

Use this as the fourth argument of `req` to specify that you want to interpret the response body as a strict `ByteString`.

data LbsResponse Source #

Make a request and interpret the body of the response as a lazy `ByteString`.

#### Instances

Instances details

Show LbsResponse Source # |
Instance details Defined in Network.HTTP.Req Methods showsPrec :: Int -> LbsResponse -> ShowS Source # show :: LbsResponse -> String Source # showList :: [LbsResponse] -> ShowS Source #
HttpResponse LbsResponse Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type HttpResponseBody LbsResponse |
Instance details Defined in Network.HTTP.Req type HttpResponseBody LbsResponse = ByteString

Methods

toVanillaResponse :: LbsResponse -> Response (HttpResponseBody LbsResponse) Source #

getHttpResponse :: Response BodyReader -> IO LbsResponse Source #

acceptHeader :: Proxy LbsResponse -> Maybe ByteString Source #

type HttpResponseBody LbsResponse Source # |
Instance details Defined in Network.HTTP.Req type HttpResponseBody LbsResponse = ByteString

lbsResponse :: Proxy LbsResponse Source #

Use this as the fourth argument of `req` to specify that you want to interpret the response body as a lazy `ByteString`.

## Inspecting a response

responseBody :: HttpResponse response => response -> HttpResponseBody response Source #

Get the response body.

responseStatusCode :: HttpResponse response => response -> Int Source #

Get the response status code.

responseStatusMessage :: HttpResponse response => response -> ByteString Source #

Get the response status message.

responseHeader Source #

Arguments

:: HttpResponse response |
=> response | Response interpretation
-> ByteString | Header to lookup
-> Maybe ByteString | Header value if found

Lookup a particular header from a response.

responseCookieJar :: HttpResponse response => response -> CookieJar Source #

Get the response `CookieJar`.

## Defining your own interpretation

To create a new response interpretation you just need to make your data type an instance of the `HttpResponse` type class.

class HttpResponse response where Source #

A type class for response interpretations. It allows us to describe how to consume the response from a ``Response` `BodyReader`` and produce the final result that is to be returned to the user.

Minimal complete definition

toVanillaResponse, getHttpResponse

Associated Types

type HttpResponseBody response Source #

The associated type is the type of body that can be extracted from an instance of `HttpResponse`.

Methods

toVanillaResponse :: response -> Response (HttpResponseBody response) Source #

The method describes how to get the underlying `Response` record.

getHttpResponse Source #

Arguments

:: Response BodyReader | Response with body reader inside
-> IO response | The final result

This method describes how to consume response body and, more generally, obtain `response` value from ``Response` `BodyReader``.

Note: `BodyReader` is nothing but ``IO` `ByteString``. You should call this action repeatedly until it yields the empty `ByteString`. In that case streaming of response is finished (which apparently leads to closing of the connection, so don't call the reader after it has returned the empty `ByteString` once) and you can concatenate the chunks to obtain the final result. (Of course you could as well stream the contents to a file or do whatever you want.)

Note: signature of this function was changed in the version 1.0.0.

acceptHeader :: Proxy response -> Maybe ByteString Source #

The value of `"Accept"` header. This is useful, for example, if a website supports both `XML` and `JSON` responses, and decides what to reply with based on what `Accept` headers you have sent.

Note: manually specified `Options` that set the `"Accept"` header will take precedence.

Since: 2.1.0

#### Instances

Instances details

HttpResponse BsResponse Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type HttpResponseBody BsResponse |
Instance details Defined in Network.HTTP.Req type HttpResponseBody BsResponse = ByteString

Methods

toVanillaResponse :: BsResponse -> Response (HttpResponseBody BsResponse) Source #

getHttpResponse :: Response BodyReader -> IO BsResponse Source #

acceptHeader :: Proxy BsResponse -> Maybe ByteString Source #

HttpResponse IgnoreResponse Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type HttpResponseBody IgnoreResponse |
Instance details Defined in Network.HTTP.Req type HttpResponseBody IgnoreResponse = ()

Methods

toVanillaResponse :: IgnoreResponse -> Response (HttpResponseBody IgnoreResponse) Source #

getHttpResponse :: Response BodyReader -> IO IgnoreResponse Source #

acceptHeader :: Proxy IgnoreResponse -> Maybe ByteString Source #

HttpResponse LbsResponse Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type HttpResponseBody LbsResponse |
Instance details Defined in Network.HTTP.Req type HttpResponseBody LbsResponse = ByteString

Methods

toVanillaResponse :: LbsResponse -> Response (HttpResponseBody LbsResponse) Source #

getHttpResponse :: Response BodyReader -> IO LbsResponse Source #

acceptHeader :: Proxy LbsResponse -> Maybe ByteString Source #

HttpResponse (Response ()) Source # | This instance has been added to make it easier to inspect `Response` using Req's functions like `responseStatusCode`, `responseStatusMessage`, etc. Since: 3.12.0

Instance details

Defined in Network.HTTP.Req

Associated Types

type HttpResponseBody (Response ()) |
Instance details Defined in Network.HTTP.Req type HttpResponseBody (Response ()) = ()

Methods

toVanillaResponse :: Response () -> Response (HttpResponseBody (Response ())) Source #

getHttpResponse :: Response BodyReader -> IO (Response ()) Source #

acceptHeader :: Proxy (Response ()) -> Maybe ByteString Source #

FromJSON a => HttpResponse (JsonResponse a) Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type HttpResponseBody (JsonResponse a) |
Instance details Defined in Network.HTTP.Req type HttpResponseBody (JsonResponse a) = a

Methods

toVanillaResponse :: JsonResponse a -> Response (HttpResponseBody (JsonResponse a)) Source #

getHttpResponse :: Response BodyReader -> IO (JsonResponse a) Source #

acceptHeader :: Proxy (JsonResponse a) -> Maybe ByteString Source #

# Other

data HttpException Source #

Exceptions that this library throws.

Constructors

VanillaHttpException HttpException | A wrapper with an `HttpException` from Network.HTTP.Client
JsonHttpException String | A wrapper with Aeson-produced `String` describing why decoding failed

#### Instances

Instances details

Exception HttpException Source # |
Instance details Defined in Network.HTTP.Req Methods toException :: HttpException -> SomeException Source # fromException :: SomeException -> Maybe HttpException Source # displayException :: HttpException -> String Source # backtraceDesired :: HttpException -> Bool Source #
Generic HttpException Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type Rep HttpException |

Instance details

Defined in Network.HTTP.Req

type Rep HttpException = D1 ('MetaData "HttpException" "Network.HTTP.Req" "req-3.13.4-1ZBL5mTVSOW64mQjyFszs4" 'False) (C1 ('MetaCons "VanillaHttpException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HttpException)) :+: C1 ('MetaCons "JsonHttpException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)))

Methods

from :: HttpException -> Rep HttpException x Source #

to :: Rep HttpException x -> HttpException Source #

Show HttpException Source # |
Instance details Defined in Network.HTTP.Req Methods showsPrec :: Int -> HttpException -> ShowS Source # show :: HttpException -> String Source # showList :: [HttpException] -> ShowS Source #
type Rep HttpException Source # |

Instance details

Defined in Network.HTTP.Req

type Rep HttpException = D1 ('MetaData "HttpException" "Network.HTTP.Req" "req-3.13.4-1ZBL5mTVSOW64mQjyFszs4" 'False) (C1 ('MetaCons "VanillaHttpException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 HttpException)) :+: C1 ('MetaCons "JsonHttpException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)))

isStatusCodeException :: HttpException -> Maybe (Response ()) Source #

Return `Just` if the given `HttpException` is wrapping a http-client's `StatusCodeException`. Otherwise, return `Nothing`.

Since: 3.12.0

data CanHaveBody Source #

A simple type isomorphic to `Bool` that we only have for better error messages. We use it as a kind and its data constructors as type-level tags.

See also: `HttpMethod` and `HttpBody`.

Constructors

CanHaveBody | Indeed can have a body
NoBody | Should not have a body

data Scheme Source #

A type-level tag that specifies URL scheme used (and thus if HTTPS is enabled). This is used to force TLS requirement for some authentication `Option`s.

Constructors

Http | HTTP
Https | HTTPS

#### Instances

Instances details

Data Scheme Source # |

Instance details

Defined in Network.HTTP.Req

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Scheme -> c Scheme Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Scheme Source #

toConstr :: Scheme -> Constr Source #

dataTypeOf :: Scheme -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Scheme) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Scheme) Source #

gmapT :: (forall b. Data b => b -> b) -> Scheme -> Scheme Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Scheme -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Scheme -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Scheme -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Scheme -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Scheme -> m Scheme Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Scheme -> m Scheme Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Scheme -> m Scheme Source #

Generic Scheme Source # |

Instance details

Defined in Network.HTTP.Req

Associated Types

type Rep Scheme |
Instance details Defined in Network.HTTP.Req type Rep Scheme = D1 ('MetaData "Scheme" "Network.HTTP.Req" "req-3.13.4-1ZBL5mTVSOW64mQjyFszs4" 'False) (C1 ('MetaCons "Http" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Https" 'PrefixI 'False) (U1 :: Type -> Type))

Methods

from :: Scheme -> Rep Scheme x Source #

to :: Rep Scheme x -> Scheme Source #

Show Scheme Source # |
Instance details Defined in Network.HTTP.Req Methods showsPrec :: Int -> Scheme -> ShowS Source # show :: Scheme -> String Source # showList :: [Scheme] -> ShowS Source #
Eq Scheme Source # |
Instance details Defined in Network.HTTP.Req Methods (==) :: Scheme -> Scheme -> Bool Source # (/=) :: Scheme -> Scheme -> Bool Source #
Ord Scheme Source # |
Instance details Defined in Network.HTTP.Req Methods compare :: Scheme -> Scheme -> Ordering Source # (<) :: Scheme -> Scheme -> Bool Source # (<=) :: Scheme -> Scheme -> Bool Source # (>) :: Scheme -> Scheme -> Bool Source # (>=) :: Scheme -> Scheme -> Bool Source # max :: Scheme -> Scheme -> Scheme Source # min :: Scheme -> Scheme -> Scheme Source #
Lift Scheme Source # |
Instance details Defined in Network.HTTP.Req Methods lift :: Quote m => Scheme -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => Scheme -> Code m Scheme Source #
type Rep Scheme Source # |
Instance details Defined in Network.HTTP.Req type Rep Scheme = D1 ('MetaData "Scheme" "Network.HTTP.Req" "req-3.13.4-1ZBL5mTVSOW64mQjyFszs4" 'False) (C1 ('MetaCons "Http" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Https" 'PrefixI 'False) (U1 :: Type -> Type))