Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- newtype RequestId = RequestId {}
- empty :: Request
- accept :: ByteString -> Request -> Request
- acceptJson :: Request -> Request
- acceptProtobuf :: Request -> Request
- body :: RequestBody -> Request -> Request
- bytes :: ByteString -> Request -> Request
- lbytes :: ByteString -> Request -> Request
- lbytesChunkedIO :: MonadIO m => ByteString -> m (Request -> Request)
- lbytesRefChunked :: IORef [ByteString] -> Request -> Request
- lbytesRefPopper :: IORef [ByteString] -> GivesPopper ()
- json :: ToJSON a => a -> Request -> Request
- jsonChunkedIO :: (ToJSON a, MonadIO m) => a -> m (Request -> Request)
- content :: ByteString -> Request -> Request
- contentJson :: Request -> Request
- contentProtobuf :: Request -> Request
- header :: HeaderName -> ByteString -> Request -> Request
- host :: ByteString -> Request -> Request
- path :: ByteString -> Request -> Request
- paths :: [ByteString] -> Request -> Request
- port :: Word16 -> Request -> Request
- query :: Query -> Request -> Request
- queryItem :: ByteString -> ByteString -> Request -> Request
- queryItem' :: ByteString -> Maybe ByteString -> Request -> Request
- secure :: Request -> Request
- method :: StdMethod -> Request -> Request
- showRequest :: Request -> String
- noRedirect :: Request -> Request
- timeout :: Int -> Request -> Request
- expect2xx :: Request -> Request
- expect3xx :: Request -> Request
- expect4xx :: Request -> Request
- expectStatus :: (Int -> Bool) -> Request -> Request
- checkStatus :: (Status -> ResponseHeaders -> CookieJar -> Maybe SomeException) -> Request -> Request
- cookie :: Cookie -> Request -> Request
- cookieRaw :: ByteString -> ByteString -> Request -> Request
- requestId :: RequestId -> Request -> Request
- requestIdName :: HeaderName
- extHost :: URI -> Maybe ByteString
- extPort :: URI -> Maybe Word16
- data Request
- data Cookie = Cookie {}
- data CookieJar
- data RequestBody
- parseRequest :: MonadThrow m => String -> m Request
- applyBasicAuth :: ByteString -> ByteString -> Request -> Request
- urlEncodedBody :: [(ByteString, ByteString)] -> Request -> Request
- getUri :: Request -> URI
Documentation
Instances
FromJSON RequestId | |
ToJSON RequestId | |
Generic RequestId | |
Read RequestId | |
Show RequestId | |
FromByteString RequestId | |
ToByteString RequestId | |
NFData RequestId | |
Eq RequestId | |
Hashable RequestId | |
FromHttpApiData RequestId | |
DecodeWire RequestId | |
EncodeWire RequestId | |
ToSchema RequestId | |
Defined in Data.Id | |
ToBytes RequestId | |
Monad m => HasRequestId (ReaderT RequestId m) Source # | |
type Rep RequestId | |
Defined in Data.Id type Rep RequestId = D1 ('MetaData "RequestId" "Data.Id" "types-common-0.16.0-LkhhqucPLeMGZ2r1ZsnNqs" 'True) (C1 ('MetaCons "RequestId" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRequestId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) |
Builders
acceptJson :: Request -> Request Source #
acceptProtobuf :: Request -> Request Source #
lbytesChunkedIO :: MonadIO m => ByteString -> m (Request -> Request) Source #
Makes requests with Transfer-Encoding: chunked
and no Content-Length
header. Tries to ensures that the lazy bytestring is garbage collected as a
"chunk" of this bytestring is consumed. Note that it is not possible to
guarantee garbage collection as something else holding a reference to this
bytestring could stop that from happening.
A more straightforward function like this will keep the reference to the complete bytestring, which might be against the idea of using chunked encoding:
lbytesChunked bs = body (RequestBodyStreamChunked $ lbytesPopper bs) lbytesPopper bs needsPopper = do ref <- newIORef $ LC.toChunks bs lbytesRefPopper ref needsPopper
This is because the closure for lbytesPopper
keeps the reference to bs
alive. To avoid this, this function allocates an IORef
and passes that to
lbytesRefChunked
.
lbytesRefChunked :: IORef [ByteString] -> Request -> Request Source #
Takes IORef
to chunks of strict ByteString
(perhaps) from a lazy
Lazy.ByteString
, this helps the lazy bytestring get garbage collected as it
gets consumed. The request made will have Transfer-Encoding: chunked
and no
Content-Length
header.
See lbytesChunkedIO
for reference usage.
lbytesRefPopper :: IORef [ByteString] -> GivesPopper () Source #
json :: ToJSON a => a -> Request -> Request Source #
Not suitable for a
which translates to very large JSON (more than a few megabytes) as the
bytestring produced by JSON will get computed and stored as it is in memory
in order to compute the Content-Length
header. For making a request with
big JSON objects, please use lbytesRefChunked
jsonChunkedIO :: (ToJSON a, MonadIO m) => a -> m (Request -> Request) Source #
Like lbytesChunkedIO
but for sending a JSON body
contentJson :: Request -> Request Source #
contentProtobuf :: Request -> Request Source #
header :: HeaderName -> ByteString -> Request -> Request Source #
Add a header field.
query :: Query -> Request -> Request Source #
Set complete query string (replacing previous content).
queryItem :: ByteString -> ByteString -> Request -> Request Source #
queryItem' :: ByteString -> Maybe ByteString -> Request -> Request Source #
Add query item to request.
showRequest :: Request -> String Source #
noRedirect :: Request -> Request Source #
checkStatus :: (Status -> ResponseHeaders -> CookieJar -> Maybe SomeException) -> Request -> Request Source #
cookieRaw :: ByteString -> ByteString -> Request -> Request Source #
Re-exports
All information on how to connect to a host and what should be sent in the HTTP request.
If you simply wish to download from a URL, see parseRequest
.
The constructor for this data type is not exposed. Instead, you should use
either the defaultRequest
value, or parseRequest
to
construct from a URL, and then use the records below to make modifications.
This approach allows http-client to add configuration options without
breaking backwards compatibility.
For example, to construct a POST request, you could do something like:
initReq <- parseRequest "http://www.example.com/path" let req = initReq { method = "POST" }
For more information, please see http://www.yesodweb.com/book/settings-types.
Since 0.1.0
data RequestBody Source #
When using one of the RequestBodyStream
/ RequestBodyStreamChunked
constructors, you must ensure that the GivesPopper
can be called multiple
times. Usually this is not a problem.
The RequestBodyStreamChunked
will send a chunked request body. Note that
not all servers support this. Only use RequestBodyStreamChunked
if you
know the server you're sending to supports chunked request bodies.
Since 0.1.0
RequestBodyLBS ByteString | |
RequestBodyBS ByteString | |
RequestBodyBuilder Int64 Builder | |
RequestBodyStream Int64 (GivesPopper ()) | |
RequestBodyStreamChunked (GivesPopper ()) | |
RequestBodyIO (IO RequestBody) | Allows creation of a Since: http-client-0.4.28 |
Instances
IsString RequestBody | Since 0.4.12 |
Defined in Network.HTTP.Client.Types fromString :: String -> RequestBody # | |
Monoid RequestBody | |
Defined in Network.HTTP.Client.Types mempty :: RequestBody # mappend :: RequestBody -> RequestBody -> RequestBody # mconcat :: [RequestBody] -> RequestBody # | |
Semigroup RequestBody | |
Defined in Network.HTTP.Client.Types (<>) :: RequestBody -> RequestBody -> RequestBody # sconcat :: NonEmpty RequestBody -> RequestBody # stimes :: Integral b => b -> RequestBody -> RequestBody # |
parseRequest :: MonadThrow m => String -> m Request Source #
Convert a URL into a Request
.
This function defaults some of the values in Request
, such as setting method
to
GET
and requestHeaders
to []
.
Since this function uses MonadThrow
, the return monad can be anything that is
an instance of MonadThrow
, such as IO
or Maybe
.
You can place the request method at the beginning of the URL separated by a space, e.g.:
parseRequest "POST http://httpbin.org/post"
Note that the request method must be provided as all capital letters.
A Request
created by this function won't cause exceptions on non-2XX
response status codes.
To create a request which throws on non-2XX status codes, see parseUrlThrow
Since: http-client-0.4.30
applyBasicAuth :: ByteString -> ByteString -> Request -> Request Source #
Add a Basic Auth header (with the specified user name and password) to the given Request. Ignore error handling:
applyBasicAuth "user" "pass" $ parseRequest_ url
NOTE: The function applyDigestAuth
is provided by the http-client-tls
package instead of this package due to extra dependencies. Please use that
package if you need to use digest authentication.
Since 0.1.0
urlEncodedBody :: [(ByteString, ByteString)] -> Request -> Request Source #
Add url-encoded parameters to the Request
.
This sets a new requestBody
, adds a content-type request header and
changes the method
to POST.
Since 0.1.0