vt-utils-1.3.0.0: Vector and Text utilities

Safe HaskellNone
LanguageHaskell2010

VtUtils.HTTP

Description

HTTP utilities for server (WAI) and client

Synopsis

Documentation

httpContentTypeJSON :: Header Source #

Content-Type header for application/json type

httpRequestPath :: Request -> Text Source #

URL path string of the specified HTTP request

Arguments:

  • req :: Request: HTTP request

Return value: URL path string

httpRequestBodyText :: Request -> IO Text Source #

Reads a body of the specified HTTP request as a Text string

Arguments:

  • req :: Request: HTTP request

Return value: Request body as a Text string

httpRequestBodyJSON :: forall a. FromJSON a => Request -> IO a Source #

Reads a body of the specified HTTP request and parses it as a JSON value

Data type should be specified with a type annotation:

Example:

dt <- httpRequestBodyJSON req :: IO Foo

Data must be an instance of FromJSON

Throws an exception if request body doesn't contain valid JSON.

Arguments:

  • req :: Request: HTTP request

Return value: Request body parsed as a JSON value

httpRequestHeaders :: Request -> Vector (Text, Text) Source #

Headers of the specified HTTP request as a Vector of (name, value) pairs

Arguments:

  • req :: Request: HTTP request

Return value: Request headers as a Vector of (name, value) pairs

httpRequestHeadersMap :: Request -> HashMap Text Text Source #

Headers of the specified HTTP request as a name -> value map

Arguments:

  • req :: Request: HTTP request

Return value: Request headers as a name -> value map

httpResponseBody :: Text -> Response BodyReader -> Int -> IO ByteString Source #

Read a body of HTTP response as a lazy ByteString

Throws an exception if specified threshold is exceeded.

Arguments:

  • label :: Text: Label used for error reporting on overly-large responses
  • resp :: Response BodyReader: HTTP response
  • threshold :: Int Max response body length in bytes

Return value: Response body as a lazy ByteString

httpResponseBodyText :: Text -> Response BodyReader -> Int -> IO Text Source #

Read a body of HTTP response as a Text string

Arguments:

  • label :: Text: Label used for error reporting on overly-large responses
  • resp :: Response BodyReader: HTTP response
  • threshold :: Int Max response body length in bytes

Return value: Response body as a Text string

httpResponseBodyJSON :: forall a. FromJSON a => Text -> Response BodyReader -> Int -> IO a Source #

Read a body of HTTP response as a JSON value

Data type should be specified with a type annotation:

Example:

dt <- httpResponseBodyJSON label resp 1024 :: IO Foo

Data must be an instance of FromJSON

Throws an exception if response body doesn't contain valid JSON.

Arguments:

  • label :: Text: Label used for error reporting on overly-large responses
  • resp :: Response BodyReader: HTTP response
  • threshold :: Int Max response body length in bytes

Return value: Response body as a JSON value

httpResponseHeaders :: Response a -> Vector (Text, Text) Source #

Headers of the specified HTTP response as a Vector of (name, value) pairs

Arguments:

  • req :: Response: HTTP request

Return value: Response headers as a Vector of (name, value) pairs

httpResponseHeadersMap :: Response a -> HashMap Text Text Source #

Headers of the specified HTTP response as a name -> value map

Arguments:

  • req :: Response: HTTP request

Return value: Response headers as a name -> value map