bilge-0.22.0: Library for composing HTTP requests.
Safe HaskellSafe-Inferred
LanguageGHC2021

Bilge.Request

Synopsis

Documentation

newtype RequestId Source #

Constructors

RequestId 

Instances

Instances details
FromJSON RequestId 
Instance details

Defined in Data.Id

ToJSON RequestId 
Instance details

Defined in Data.Id

Generic RequestId 
Instance details

Defined in Data.Id

Associated Types

type Rep RequestId :: Type -> Type #

Read RequestId 
Instance details

Defined in Data.Id

Show RequestId 
Instance details

Defined in Data.Id

FromByteString RequestId 
Instance details

Defined in Data.Id

Methods

parser :: Parser RequestId Source #

ToByteString RequestId 
Instance details

Defined in Data.Id

NFData RequestId 
Instance details

Defined in Data.Id

Methods

rnf :: RequestId -> () #

Eq RequestId 
Instance details

Defined in Data.Id

Hashable RequestId 
Instance details

Defined in Data.Id

FromHttpApiData RequestId 
Instance details

Defined in Data.Id

DecodeWire RequestId 
Instance details

Defined in Data.Id

EncodeWire RequestId 
Instance details

Defined in Data.Id

ToSchema RequestId 
Instance details

Defined in Data.Id

ToBytes RequestId 
Instance details

Defined in Data.Id

Monad m => HasRequestId (ReaderT RequestId m) Source # 
Instance details

Defined in Bilge.RPC

type Rep RequestId 
Instance details

Defined in Data.Id

type Rep RequestId = D1 ('MetaData "RequestId" "Data.Id" "types-common-0.16.0-EbVXdMsk6waAiaaWLJxODo" 'True) (C1 ('MetaCons "RequestId" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRequestId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

Builders

empty :: Request Source #

The empty request.

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.

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

header :: HeaderName -> ByteString -> Request -> Request Source #

Add a header field.

query :: Query -> Request -> Request Source #

Set complete query string (replacing previous content).

queryItem' :: ByteString -> Maybe ByteString -> Request -> Request Source #

Add query item to request.

secure :: Request -> Request Source #

The request should be made over HTTPS.

timeout :: Int -> Request -> Request Source #

How many milliseconds to wait for response.

Re-exports

data Request Source #

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

Instances

Instances details
Show Request 
Instance details

Defined in Network.HTTP.Client.Types

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

Constructors

RequestBodyLBS ByteString 
RequestBodyBS ByteString 
RequestBodyBuilder Int64 Builder 
RequestBodyStream Int64 (GivesPopper ()) 
RequestBodyStreamChunked (GivesPopper ()) 
RequestBodyIO (IO RequestBody)

Allows creation of a RequestBody inside the IO monad, which is useful for making easier APIs (like setRequestBodyFile).

Since: http-client-0.4.28

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

getUri :: Request -> URI Source #

Extract a URI from the request.

Since 0.1.0