N?D]      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 2016 2017 Mark Karpov BSD 3 clause$Mark Karpov <markkarpov92@gmail.com> experimentalportableNone!",059;DIORTcA type-level tag that specifies URL scheme used (and thus if HTTPS is enabled). This is used to force TLS requirement for some authentication s.HTTPHTTPS A simple u-like type we only have for better error messages. We use it as a kind and its data constructors as type-level tags. See also: ) and .Indeed can have a bodyShould not have a body$Exceptions that this library throws.A wrapper with an  from Network.HTTP.ClientA wrapper with Aeson-produced  describing why decoding failedpThis wrapper is only used to attach a type-level tag to a given type. This is necessary to define instances of  for any thing that implements ) or 9. Without the tag, GHC can't see the difference between ) method =>  method and  body =>  body~ when it decides which instance to use (i.e. the constraints are taken into account later, when instance is already chosen)..The main class for things that are parts  of ! in the sense that if we have a ,, then we know how to apply an instance of ' changing/overwriting something in it. p is a monoid of endomorphisms under composition, it's used to chain different request components easier using ().Get a function that takes a + and changes it somehow returning another '. For example HTTP method instance of 5 just overwrites method. The function is wrapped in \ so it's easier to chain such modifying applications  together building bigger and bigger s. vA type class for response interpretations. It allows to fully control how request is made and how its body is parsed. SThe associated type is the type of body that can be extracted from an instance of  . /The method describes how to get the underlying  record. 8This method describes how to make an HTTP request given  (prepared by the library) and . Construct a preview  of response body. It is recommend to limit the length to 1024 bytes. This is mainly useful for inclusion of response body fragments in exceptions.9Make a request and interpret body of response as a lazy .:Make a request and interpret body of response as a strict .<Make a request and interpret body of response as JSON. The G method of F3 instance corresponding to monad in which you use I@ will determine what to do in the case when parsing fails (the  constructor will be used).+Make a request and ignore body of response.PA type class for query-parameter-like things. The reason to have an overloaded  is to be able to use it as an  and as a | when constructing form URL encoded request bodies. Having the same syntax for these cases seems natural and user-friendly.ACreate a query parameter with given name and value. If value is Z, it won't be included at all (i.e. you create a flag this way). It's recommended to use (S) and T: instead of this method, because they are easier to read.Opaque  type is a ~ you can use to pack collection of optional parameters like query parameters and headers. See sections below to learn which  primitives are available.;This type function allows any HTTP body if method says it &. When the method says it should have ", the only body option to use is &.Note: users of GHC 8.0.1 and later will see a slightly more friendly error message when method does not allow a body and body is provided.The type function recognizes & as having , while any other body option . This forces user to use & with <6 method and other methods that should not send a body.<A type class for things that can be interpreted as an HTTP .How to get actual .2This method allows to optionally specify value of  Content-TypeQ header that should be used with particular body option. By default it returns  and so  Content-Type is not set.)Multipart form data. Please consult the %Network.HTTP.Client.MultipartFormData. module for how to construct parts, then use R0 to create actual request body from the parts. R) is the only way to get a value of type 0, as its constructor is not exported on purpose.Example import Control.Exception (throwIO) import qualified Network.HTTP.Client.MultipartFormData as LM import Network.HTTP.Req instance MonadHttp IO where handleHttpException = throwIO main :: IO () main = do body <- reqBodyMultipart [ LM.partBS "title" "My Image" , LM.partFileSource "file1" "/tmp/image.jpg" ] response <- req POST (http "example.com" /: "post") body bsResponse mempty print $ responseBody responseYAn opaque monoidal value that allows to collect URL-encoded parameters to be wrapped in .JForm 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: (S) and T.This body option sets the  Content-Type header to #"application/x-www-from-urlencoded" value.(HTTP request body represented by a lazy .+Using of this body option does not set the  Content-Type header. *HTTP request body represented by a strict .+Using of this body option does not set the  Content-Type header."{This body option streams request body from a file. It is expected that the file size does not change during the streaming.+Using of this body option does not set the  Content-Type header.$This body option allows to use a JSON object as request body probably the most popular format right now. Just wrap a data type that is an instance of Y 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.&\This data type represents empty body of an HTTP request. This is the data type to use with )<s that cannot have a body, as it's the only type for which  returns .+Using of this body option does not set the  Content-Type header.( Request's (. Start constructing your ( with L or M@ specifying the scheme and host at the same time. Then use the (N) and (O)t operators to grow the path one piece at a time. Every single piece of path will be url(percent)-encoded, so using (N) and (O) 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 (s (make sure the OverloadedStrings language extension is enabled).Examples (http "httpbin.org" -- http://httpbin.org *https "httpbin.org" -- https://httpbin.org Phttps "httpbin.org" /: "encoding" /: "utf8" -- https://httpbin.org/encoding/utf8 Nhttps "httpbin.org" /: "foo" /: "bar/baz" -- https://httpbin.org/foo/bar%2Fbaz Mhttps "httpbin.org" /: "bytes" /~ (10 :: Int) -- https://httpbin.org/bytes/10 Nhttps "N=8:>4.@D" -- https://%D1%8E%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4.%D1%80%D1%84)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: vdata COPY = COPY instance HttpMethod COPY where type AllowsBody COPY = 'CanHaveBody httpMethodName Proxy = "COPY"*Type function * returns a type of kind j which tells the rest of the library whether the method can have a body or not. We use the special type $ lifted  to kind level instead of - to get more user-friendly compiler messages.+Return name of the method as a .,, method... method.00 method.22 method.44A method. This data type does not allow having request body with 49 requests, as it should be. However some APIs may expect 4F requests to have bodies, in that case define your own variation of 4$ method and allow it to have a body.66 method.88 method.:: method.<< method.>>M contains general and default settings to be used when making HTTP requests.@#Proxy to use. By default values of  HTTP_PROXY and  HTTPS_PROXYU environment variables are respected, this setting overwrites them. Default value: .AIHow many redirects to follow when getting a resource. Default value: 10.B Alternative  to use. k (default value) means that default implicit manager will be used (that's what you want in 99% of cases).CFunction to check the response immediately after receiving the status and headers. This is used for throwing exceptions on non-success status codes by default (set to \_ _ -> return () if this behavior is not desirable). 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. The thrown exception is caught by the library though and is available in G.D9The retry policy to use for request retrying. By default  is used (see ).E;The function is used to decide whether to retry a request. + means that the request should be retried.FgA type class for monads that support performing HTTP requests. Typically, you only need to define the G" method unless you want to tweak >.G'This method describes how to deal with  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 ), this is the right place to pass it to .HReturn >O to be used when performing HTTP requests. Default implementation returns its k value, which is described in the documentation for the type. Common usage pattern with manually defined H> is to return some hard-coded value, or value extracted from < if a more flexible approach to configuration is desirable.IlMake an HTTP request. The function takes 5 arguments, 4 of which specify required parameters and the final 2 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 < or :F. The documentation has a dedicated section about HTTP methods below.url is a (@ that describes location of resource you want to interact with.body is a body option such as & or $. The tutorial has a section about HTTP bodies, but usage is very straightforward and should be clear from the examples below.responseo is a type hint how to make and interpret response of an HTTP request. Out-of-the-box it can be the following:_`a (to get a strict )b (to get a lazy ) Finally, options is a  that holds a composite  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 .Note that if you use IV to do all your requests, connection sharing and reuse is done for you automatically.3See 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: k{-# LANGUAGE OverloadedStrings #-} module Main (main) where import Control.Exception (throwIO) import Control.Monad 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 instance MonadHttp IO where handleHttpException = throwIO'We will be making requests against the  https://httpbin.org service.(Make a GET request, grab 5 random bytes: main :: IO () main = do let n :: Int n = 5 bs <- req GET (https "httpbin.org" /: "bytes" /~ n) NoReqBody bsResponse mempty B.putStrLn (responseBody bs)1The same, but now we use a query parameter named "seed"# to control seed of the generator: main :: IO () main = do let n, seed :: Int n = 5 seed = 100 bs <- req GET (https "httpbin.org" /: "bytes" /~ n) NoReqBody bsResponse $ "seed" =: seed B.putStrLn (responseBody bs)8POST 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 = do let myData = MyData { size = 6 , color = "Green" } v <- req POST (https "httpbin.org" /: "post") (ReqBodyJson myData) jsonResponse mempty print (responseBody v :: Value)Sending URL-encoded body: main :: IO () main = do let params = "foo" =: ("bar" :: Text) <> queryFlag "baz" response <- req POST (https "httpbin.org" /: "post") (ReqBodyUrlEnc params) jsonResponse mempty print (responseBody response :: Value)GUsing various optional parameters and URL that is not known in advance: Amain :: IO () main = 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'. let (url, options) = fromJust (parseUrlHttps "https://httpbin.org/get?foo=bar") 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 print (responseBody response :: Value)J Mostly like In with respect to its arguments, but accepts a callback that allows to perform a request in arbitrary fashion.This function does notZ perform handling/wrapping exceptions, checking response, and retrying. It only prepares  and allows you to use it.Global  that I uses. Here we just go with the default settings, so users don't need to deal with this manager stuff at all, but when we create a request, instance >& can affect the default settings via H.A note about safety, in case ( looks suspicious to you. The value of  is named and lives on top level. This means it will be shared, i.e. computed only once on the first use of the manager. From that moment on the  will be just reused exactly the behavior we want here in order to maximize connection sharing. GHC could spoil the plan by inlining the definition, hence the NOINLINE pragma.K(Perform an action using global implicit O that the rest of the library uses. This allows to reuse connections that the  controls.LGiven host name, produce a (I which have http  as its scheme and empty path. This also sets port to 80.MGiven host name, produce a (J which have https  as its scheme and empty path. This also sets port to 443.N Grow given (n appending a single path segment to it. Note that the path segment can be of any type that is an instance of .OType-constrained version of (N)< to remove ambiguity in the cases when next URL piece is a  literal.PThe P0 function provides an alternative method to get ( (possibly with some  s) from a s. This is useful when you are given a URL to query dynamically and don't know it beforehand. The function parses 7 because it's the correct type to represent a URL, as ([ cannot contain characters outside of ASCII range, thus we can consider every character a  value.This function only parses (J (scheme, host, path) and optional query parameters that are returned as C. It does not parse method name or authentication info from given .Q Just like P, but expects https  scheme.WGet host/collection of path pieces and possibly query parameters already converted to . This function is not public.RCreate # request body from a collection of s.A helper to create an a that modifies only collection of query parameters. This helper is not a part of the public API.A helper to create an  that modifies only +. This helper is not a part of public API.A helper to create an _ that adds a finalizer (request transformation that is applied after all other modifications).Finalize given ) by applying a finalizer from the given  (if it has any).SiThis operator builds a query parameter that will be included in URL of your request after question sign ?H. This is the same syntax you use with form URL encoded request bodies.%This operator is defined in terms of : ,name =: value = queryParam name (pure value)TYConstruct a flag, that is, 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 : 6queryFlag name = queryParam name (Nothing :: Maybe ())U Create an & that adds a header. Note that if you  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.MA non-public helper that attaches a header with given name and content to a .VUse the given . A  can be obtained from a  record.WThe  adds basic authentication. See also:  9https://en.wikipedia.org/wiki/Basic_access_authentication.XThe  adds OAuth1 authentication.YThe m adds an OAuth2 bearer token. This is treated by many services as the equivalent of a username and password.The  is defined as: @oAuth2Bearer token = header "Authorization" ("Bearer " <> token) See also:  #https://en.wikipedia.org/wiki/OAuth.ZThe  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  is defined as: =oAuth2Token token = header "Authorization" ("token" <> token) See also:  Nhttps://developer.github.com/v3/oauth#3-use-the-access-token-to-access-the-api.[5Specify the port to connect to explicitly. Normally, (' you use determines the default port: 80 for HTTP and 443 for HTTPS. This : allows to choose arbitrary port overwriting the defaults.\This d 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")7You can also choose to decompress everything like this: decompress (const True)]ZSpecify the number of microseconds to wait for response. The default value is 30 seconds.^<HTTP version to send to the server, the default is HTTP 1.1._#Use this as the fourth argument of I, to specify that you want it to return the  interpretation.`"Use this as the forth argument of I, to specify that you want it to return the  interpretation.a"Use this as the forth argument of IB to specify that you want to interpret response body as a strict .b"Use this as the forth argument of I@ to specify that you want to interpret response body as a lazy .cGet the response body.dGet the response status code.e Get the response status message.f+Lookup a particular header from a response.gGet the response .0Max length of preview fragment of response body.  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI HTTP method( location of resourceBody of the request A hint how to interpret response!Collection of optional parametersResponseJ HTTP method( location of resourceBody of the request!Collection of optional parametersHow to perform requestKLMNOPQRSTU Header name Header valueVWUsernamePasswordAuth XConsumer tokenConsumer secret OAuth tokenOAuth token secretAuth YTokenAuth ZTokenAuth [\/Predicate that is given MIME type, it returns 0 when content should be decompressed on the fly.]Number of microseconds to wait^Major version numberMinor version number_`abcdefResponse interpretationHeader to lookupHeader value if foundghijklmnopqrstuvwxyz{|}~h  !"#$%&'()*+,-./0123456789:;<=>?DEC@ABFHGIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghIJKFGH>?@ABCDE<=:;8967452301./,-)*+(LMNOPQ&'$%"# !RSTUVWXYZ[\]^_`abcdefg j   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~N5O5S7       !"#$$%%&&''(())*+,-..//001122334455667789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"#* req-0.3.0-ElQUrnt9Bx8KKm33XluNFtNetwork.HTTP.ReqControl.Monad.Except MonadError throwErrorControl.Monad.Reader MonadReader Data.WordWord8SchemeHttpHttps CanHaveBodyNoBody HttpExceptionVanillaHttpExceptionJsonHttpException HttpResponseHttpResponseBodytoVanillaResponsegetHttpResponsemakeResponseBodyPreview LbsResponse BsResponse JsonResponseIgnoreResponse QueryParam queryParamOptionHttpBodyAllowed ProvidesBodyHttpBodygetRequestBodygetRequestContentTypeReqBodyMultipartFormUrlEncodedParam ReqBodyUrlEnc ReqBodyLbs ReqBodyBs ReqBodyFile ReqBodyJson NoReqBodyUrl HttpMethod AllowsBodyhttpMethodNamePATCHOPTIONSCONNECTTRACEDELETEPUTHEADPOSTGET HttpConfighttpConfigProxyhttpConfigRedirectCounthttpConfigAltManagerhttpConfigCheckResponsehttpConfigRetryPolicyhttpConfigRetryJudge MonadHttphandleHttpException getHttpConfigreqreq'withReqManagerhttphttps/~/: parseUrlHttp parseUrlHttpsreqBodyMultipart=: queryFlagheader cookieJar basicAuthoAuth1 oAuth2Bearer oAuth2Tokenport decompressresponseTimeout httpVersionignoreResponse jsonResponse bsResponse lbsResponse responseBodyresponseStatusCoderesponseStatusMessageresponseHeaderresponseCookieJar$fExceptionHttpException$fHttpResponseLbsResponse$fHttpResponseBsResponse$fHttpResponseJsonResponse$fHttpResponseIgnoreResponse$fQueryParamOption$fRequestComponentOption$fMonoidOption$fSemigroupOption$fRequestComponentWomb$fHttpBodyReqBodyMultipart$fQueryParamFormUrlEncodedParam$fHttpBodyReqBodyUrlEnc$fHttpBodyReqBodyLbs$fHttpBodyReqBodyBs$fHttpBodyReqBodyFile$fHttpBodyReqBodyJson$fHttpBodyNoReqBody$fRequestComponentUrl$fRequestComponentWomb0$fHttpMethodPATCH$fHttpMethodOPTIONS$fHttpMethodCONNECT$fHttpMethodTRACE$fHttpMethodDELETE$fHttpMethodPUT$fHttpMethodHEAD$fHttpMethodPOST$fHttpMethodGET$fRequestComponentHttpConfig$fDefaultHttpConfig$fSemigroupFormUrlEncodedParam$fMonoidFormUrlEncodedParam$fShowHttpException$fGenericHttpException $fEqScheme $fOrdScheme $fShowScheme $fDataScheme$fGenericScheme$fEqUrl$fOrdUrl $fShowUrl $fDataUrl $fGenericUrlghc-prim GHC.TypesBool*http-client-0.5.7.0-DXA0IEg6NkS4iccVjaYe76Network.HTTP.Client.TypesbaseGHC.BaseStringWombRequestComponentRequest Data.MonoidEndoData.Semigroup<> getRequestModResponseManagerbytestring-0.10.8.1Data.ByteString.Lazy.Internal ByteStringData.ByteString.InternalNothingMonoid RequestBody$aeson-1.2.1.0-JNk6H1JAeYYGIlsiSuwv5rData.Aeson.Types.ToJSONToJSON0data-default-class-0.1.2.0-GsXqKN6o1X9jr0fF5qCVDData.Default.Classdef#retry-0.7.4.2-nE9FeIcoOFBULkCbmo88B Control.Retry RetryPolicyMTruemempty globalManager GHC.IO.UnsafeunsafePerformIO GHC.IORefIORef,http-api-data-0.3.7.1-2Q46RE2tiOeJsB462PjSTHWeb.Internal.HttpApiData ToHttpApiData#text-1.2.2.2-KC7dWoG09dA1F6jKj5GSqhData.Text.InternalTextparseUrlHelper%Network.HTTP.Client.MultipartFormDataPartwithQueryParams withRequest asFinalizerfinalizeRequestmappend attachHeader CookieJarbodyPreviewLength