webapi-0.2.2.0: WAI based library for web api

LicenseBSD3
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

WebApi.Client

Contents

Description

Provides a client for a web api for a given contract.

Synopsis

Client related functions

client :: forall m r. (CookieOut m r ~ (), ToParam (PathParam m r) PathParam, ToParam (QueryParam m r) QueryParam, ToParam (FormParam m r) FormParam, ToHeader (HeaderIn m r), ToParam (FileParam m r) FileParam, FromHeader (HeaderOut m r), Decodings (ContentTypes m r) (ApiOut m r), Decodings (ContentTypes m r) (ApiErr m r), SingMethod m, MkPathFormatString r, PartEncodings (RequestBody m r), ToHListRecTuple (StripContents (RequestBody m r))) => ClientSettings -> Request m r -> IO (Response m r) Source

Given a Request type, create the request and obtain a response. Gives back a Response.

fromClientResponse :: forall m r. (FromHeader (HeaderOut m r), Decodings (ContentTypes m r) (ApiOut m r), Decodings (ContentTypes m r) (ApiErr m r), CookieOut m r ~ ()) => Response BodyReader -> IO (Response m r) Source

Creates the Response type from the response body.

link :: (ToParam (QueryParam m r) QueryParam, MkPathFormatString r, ToParam (PathParam m r) PathParam) => route m r -> URI -> PathParam m r -> Maybe (QueryParam m r) -> URI Source

Generate a type safe URL for a given route type. The URI can be used for setting a base URL if required.

Types

data ClientSettings Source

Datatype representing the settings related to client.

Constructors

ClientSettings 

Fields

baseUrl :: String

base url of the API being called.

connectionManager :: Manager

connection manager for the connection.

data UnknownClientException Source

This exception is used to signal an irrecoverable error while deserializing the response.

Connection manager

data Manager :: *

Keeps track of open connections for keep-alive.

If possible, you should share a single Manager between multiple threads and requests.

Since 0.1.0

newManager :: ManagerSettings -> IO Manager

Create a Manager. The Manager will be shut down automatically via garbage collection.

Creating a new Manager is a relatively expensive operation, you are advised to share a single Manager between requests instead.

The first argument to this function is often defaultManagerSettings, though add-on libraries may provide a recommended replacement.

Since 0.1.0

closeManager :: Manager -> IO ()

Close all connections in a Manager.

Note that this doesn't affect currently in-flight connections, meaning you can safely use it without hurting any queries you may have concurrently running.

Since 0.1.0

withManager :: ManagerSettings -> (Manager -> IO a) -> IO a

Create, use and close a Manager.

Since 0.2.1

class HasHttpManager a where

Methods

getHttpManager :: a -> Manager

Connection manager settings

data ManagerSettings :: *

Settings for a Manager. Please use the defaultManagerSettings function and then modify individual settings. For more information, see http://www.yesodweb.com/book/settings-types.

Since 0.1.0

defaultManagerSettings :: ManagerSettings

Default value for ManagerSettings.

Note that this value does not have support for SSL/TLS. If you need to make any https connections, please use the http-client-tls package, which provides a tlsManagerSettings value.

Since 0.1.0

tlsManagerSettings :: ManagerSettings

Default TLS-enabled manager settings