servant-0.20.1: A family of combinators for defining webservices APIs
Safe HaskellNone
LanguageHaskell2010

Servant.API

Synopsis

Combinators

Type-level combinator for expressing subrouting: :>

Type-level combinator for alternative endpoints: :<|>

Type-level combinator for an empty API: EmptyAPI

data Strict #

Strictly parsed argument. Not wrapped.

Instances

Instances details
(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a

HasResponseHeader h a (Header h a ': rest) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

hlistLookupHeader :: HList (Header h a ': rest) -> ResponseHeader h a

(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header h v ': xs) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

buildHeadersTo :: [Header] -> HList (Header h v ': xs) #

(KnownSymbol h, GetHeadersFromHList rest, ToHttpApiData v) => GetHeaders' (Header h v ': rest) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

getHeaders' :: Headers (Header h v ': rest) a -> [Header]

data Lenient #

Leniently parsed argument, i.e. parsing never fail. Wrapped in Either Text.

data Optional #

Optional argument. Wrapped in Maybe.

Instances

Instances details
(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a

HasResponseHeader h a (Header h a ': rest) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

hlistLookupHeader :: HList (Header h a ': rest) -> ResponseHeader h a

(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header h v ': xs) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

buildHeadersTo :: [Header] -> HList (Header h v ': xs) #

(KnownSymbol h, GetHeadersFromHList rest, ToHttpApiData v) => GetHeaders' (Header h v ': rest) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

getHeaders' :: Headers (Header h v ': rest) a -> [Header]

data Required #

Required argument. Not wrapped.

Type-level modifiers for QueryParam, Header and ReqBody.

Accessing information from the request

Capturing parts of the url path as parsed values: Capture and CaptureAll

Retrieving specific headers from the request

Retrieving the HTTP version of the request

Retrieving parameters from the query string of the URI: QueryParam

Documenting the fragment of the URI: Fragment

Accessing the request body as a JSON-encoded type: ReqBody

Retrieving the IP of the client

Is the request made through HTTPS?

Access the location for arbitrary data to be shared by applications and middleware

Access context entries in combinators in servant-server

Access a managed resource scoped to a single request

Actual endpoints, distinguished by HTTP method

type Get = Verb 'GET 200 #

GET with 200 status code.

type Put = Verb 'PUT 200 #

PUT with 200 status code.

data StdMethod #

HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).

Since: http-types-0.2.0

Constructors

GET 
POST 
HEAD 
PUT 
DELETE 
TRACE 
CONNECT 
OPTIONS 
PATCH

Since: http-types-0.8.0

Instances

Instances details
Data StdMethod

Since: http-types-0.12.4

Instance details

Defined in Network.HTTP.Types.Method

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> StdMethod -> c StdMethod #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c StdMethod #

toConstr :: StdMethod -> Constr #

dataTypeOf :: StdMethod -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c StdMethod) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c StdMethod) #

gmapT :: (forall b. Data b => b -> b) -> StdMethod -> StdMethod #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> StdMethod -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> StdMethod -> r #

gmapQ :: (forall d. Data d => d -> u) -> StdMethod -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> StdMethod -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> StdMethod -> m StdMethod #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> StdMethod -> m StdMethod #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> StdMethod -> m StdMethod #

Bounded StdMethod 
Instance details

Defined in Network.HTTP.Types.Method

Enum StdMethod 
Instance details

Defined in Network.HTTP.Types.Method

Generic StdMethod 
Instance details

Defined in Network.HTTP.Types.Method

Associated Types

type Rep StdMethod

Since: http-types-0.12.4

Instance details

Defined in Network.HTTP.Types.Method

type Rep StdMethod = D1 ('MetaData "StdMethod" "Network.HTTP.Types.Method" "http-types-0.12.4-2SFJ3KLUooQ7yK2zJjjEEI" 'False) (((C1 ('MetaCons "GET" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "POST" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "HEAD" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PUT" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "DELETE" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TRACE" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CONNECT" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OPTIONS" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PATCH" 'PrefixI 'False) (U1 :: Type -> Type)))))
Ix StdMethod 
Instance details

Defined in Network.HTTP.Types.Method

Read StdMethod 
Instance details

Defined in Network.HTTP.Types.Method

Show StdMethod 
Instance details

Defined in Network.HTTP.Types.Method

Eq StdMethod 
Instance details

Defined in Network.HTTP.Types.Method

Ord StdMethod 
Instance details

Defined in Network.HTTP.Types.Method

ReflectMethod 'CONNECT # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'DELETE # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'GET # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'HEAD # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'OPTIONS # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'PATCH # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'POST # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'PUT # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'TRACE # 
Instance details

Defined in Servant.API.Verbs

type Rep StdMethod

Since: http-types-0.12.4

Instance details

Defined in Network.HTTP.Types.Method

type Rep StdMethod = D1 ('MetaData "StdMethod" "Network.HTTP.Types.Method" "http-types-0.12.4-2SFJ3KLUooQ7yK2zJjjEEI" 'False) (((C1 ('MetaCons "GET" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "POST" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "HEAD" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PUT" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "DELETE" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TRACE" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "CONNECT" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "OPTIONS" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PATCH" 'PrefixI 'False) (U1 :: Type -> Type)))))

type Delete = Verb 'DELETE 200 #

DELETE with 200 status code.

type DeleteAccepted = Verb 'DELETE 202 #

DELETE with 202 status code.

type DeleteNoContent = NoContentVerb 'DELETE #

DELETE with 204 status code.

type DeleteNonAuthoritative = Verb 'DELETE 203 #

DELETE with 203 status code.

type GetAccepted = Verb 'GET 202 #

GET with 202 status code.

type GetNoContent = NoContentVerb 'GET #

GET with 204 status code.

type GetNonAuthoritative = Verb 'GET 203 #

GET with 203 status code.

type GetPartialContent = Verb 'GET 206 #

GET with 206 status code.

type GetResetContent = Verb 'GET 205 #

GET with 205 status code.

data NoContentVerb (method :: k1) #

NoContentVerb is a specific type to represent NoContent responses. It does not require either a list of content types (because there's no content) or a status code (because it should always be 204).

Instances

Instances details
HasLink (NoContentVerb m :: Type) # 
Instance details

Defined in Servant.Links

Methods

toLink :: (Link -> a) -> Proxy (NoContentVerb m) -> Link -> MkLink (NoContentVerb m) a #

Generic (NoContentVerb method) # 
Instance details

Defined in Servant.API.Verbs

Associated Types

type Rep (NoContentVerb method) 
Instance details

Defined in Servant.API.Verbs

type Rep (NoContentVerb method) = D1 ('MetaData "NoContentVerb" "Servant.API.Verbs" "servant-0.20.1-DlxSeFXhWhX4WccYlHDTNj" 'False) (V1 :: Type -> Type)

Methods

from :: NoContentVerb method -> Rep (NoContentVerb method) x #

to :: Rep (NoContentVerb method) x -> NoContentVerb method #

type MkLink (NoContentVerb m :: Type) r # 
Instance details

Defined in Servant.Links

type MkLink (NoContentVerb m :: Type) r = r
type Rep (NoContentVerb method) # 
Instance details

Defined in Servant.API.Verbs

type Rep (NoContentVerb method) = D1 ('MetaData "NoContentVerb" "Servant.API.Verbs" "servant-0.20.1-DlxSeFXhWhX4WccYlHDTNj" 'False) (V1 :: Type -> Type)

type Patch = Verb 'PATCH 200 #

PATCH with 200 status code.

type PatchAccepted = Verb 'PATCH 202 #

PATCH with 202 status code.

type PatchNoContent = NoContentVerb 'PATCH #

PATCH with 204 status code.

type PatchNonAuthoritative = Verb 'PATCH 203 #

PATCH with 203 status code.

type Post = Verb 'POST 200 #

POST with 200 status code.

type PostAccepted = Verb 'POST 202 #

POST with 202 status code.

type PostCreated = Verb 'POST 201 #

POST with 201 status code.

type PostNoContent = NoContentVerb 'POST #

POST with 204 status code.

type PostNonAuthoritative = Verb 'POST 203 #

POST with 203 status code.

type PostResetContent = Verb 'POST 205 #

POST with 205 status code.

type PutAccepted = Verb 'PUT 202 #

PUT with 202 status code.

type PutCreated = Verb 'PUT 201 #

PUT with 201 status code.

type PutNoContent = NoContentVerb 'PUT #

PUT with 204 status code.

type PutNonAuthoritative = Verb 'PUT 203 #

PUT with 203 status code.

class ReflectMethod (a :: k) where #

Methods

reflectMethod :: Proxy a -> Method #

Instances

Instances details
ReflectMethod 'CONNECT # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'DELETE # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'GET # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'HEAD # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'OPTIONS # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'PATCH # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'POST # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'PUT # 
Instance details

Defined in Servant.API.Verbs

ReflectMethod 'TRACE # 
Instance details

Defined in Servant.API.Verbs

data Verb (method :: k1) (statusCode :: Nat) (contentTypes :: [Type]) a #

Verb is a general type for representing HTTP verbs (a.k.a. methods). For convenience, type synonyms for each verb with a 200 response code are provided, but you are free to define your own:

>>> type Post204 contentTypes a = Verb 'POST 204 contentTypes a

Instances

Instances details
HasLink (Verb m s ct a :: Type) # 
Instance details

Defined in Servant.Links

Methods

toLink :: (Link -> a0) -> Proxy (Verb m s ct a) -> Link -> MkLink (Verb m s ct a) a0 #

Generic (Verb method statusCode contentTypes a) # 
Instance details

Defined in Servant.API.Verbs

Associated Types

type Rep (Verb method statusCode contentTypes a) 
Instance details

Defined in Servant.API.Verbs

type Rep (Verb method statusCode contentTypes a) = D1 ('MetaData "Verb" "Servant.API.Verbs" "servant-0.20.1-DlxSeFXhWhX4WccYlHDTNj" 'False) (V1 :: Type -> Type)

Methods

from :: Verb method statusCode contentTypes a -> Rep (Verb method statusCode contentTypes a) x #

to :: Rep (Verb method statusCode contentTypes a) x -> Verb method statusCode contentTypes a #

AtLeastOneFragment (Verb m s ct typ) #

If fragment appeared in API endpoint twice, compile-time error would be raised.

>>> -- type FailAPI = Fragment Bool :> Fragment Int :> Get '[JSON] NoContent
>>> instance AtLeastOneFragment FailAPI
...
...Only one Fragment allowed per endpoint in api...
...
...In the instance declaration for...
Instance details

Defined in Servant.API.TypeLevel

type MkLink (Verb m s ct a :: Type) r # 
Instance details

Defined in Servant.Links

type MkLink (Verb m s ct a :: Type) r = r
type Rep (Verb method statusCode contentTypes a) # 
Instance details

Defined in Servant.API.Verbs

type Rep (Verb method statusCode contentTypes a) = D1 ('MetaData "Verb" "Servant.API.Verbs" "servant-0.20.1-DlxSeFXhWhX4WccYlHDTNj" 'False) (V1 :: Type -> Type)

type family Unique (xs :: [k]) where ... #

Check whether all values in a type-level list are distinct. This will throw a nice error if there are any duplicate elements in the list.

Equations

Unique (xs :: [k]) = If (Nubbed xs == 'True) () (TypeError (DuplicateElementError xs) :: Constraint) 

type Union = NS I #

data UVerb (method :: StdMethod) (contentTypes :: [Type]) (as :: [Type]) #

A variant of Verb that can have any of a number of response values and status codes.

FUTUREWORK: it would be nice to make Verb a special case of UVerb, and only write instances for HasServer etc. for the latter, getting them for the former for free. Something like:

type Verb method statusCode contentTypes a = UVerb method contentTypes [WithStatus statusCode a]

Backwards compatibility is tricky, though: this type alias would mean people would have to use respond instead of pure or return, so all old handlers would have to be rewritten.

Instances

Instances details
HasLink (UVerb m ct a :: Type) # 
Instance details

Defined in Servant.Links

Methods

toLink :: (Link -> a0) -> Proxy (UVerb m ct a) -> Link -> MkLink (UVerb m ct a) a0 #

AtLeastOneFragment (UVerb m cts as) # 
Instance details

Defined in Servant.API.TypeLevel

type MkLink (UVerb m ct a :: Type) r # 
Instance details

Defined in Servant.Links

type MkLink (UVerb m ct a :: Type) r = r

class KnownStatus (StatusOf a) => HasStatus a #

Associated Types

type StatusOf a :: Nat #

Instances

Instances details
HasStatus NoContent #

If an API can respond with NoContent we assume that this will happen with the status code 204 No Content. If this needs to be overridden, WithStatus can be used.

Instance details

Defined in Servant.API.UVerb

Associated Types

type StatusOf NoContent 
Instance details

Defined in Servant.API.UVerb

type StatusOf NoContent = 204
HasStatus a => HasStatus (Headers ls a) # 
Instance details

Defined in Servant.API.UVerb

Associated Types

type StatusOf (Headers ls a) 
Instance details

Defined in Servant.API.UVerb

type StatusOf (Headers ls a) = StatusOf a
KnownStatus n => HasStatus (WithStatus n a) #

an instance of this typeclass assigns a HTTP status code to a return type

Example:

   data NotFoundError = NotFoundError String

   instance HasStatus NotFoundError where
     type StatusOf NotFoundError = 404

You can also use the convience newtype wrapper WithStatus if you want to avoid writing a HasStatus instance manually. It also has the benefit of showing the status code in the type; which might aid in readability.

Instance details

Defined in Servant.API.UVerb

Associated Types

type StatusOf (WithStatus n a) 
Instance details

Defined in Servant.API.UVerb

type StatusOf (WithStatus n a) = n

type IsMember (a :: u) (as :: [u]) = (Unique as, CheckElemIsMember a as, UElem a as) #

type family StatusOf a :: Nat #

Instances

Instances details
type StatusOf NoContent # 
Instance details

Defined in Servant.API.UVerb

type StatusOf NoContent = 204
type StatusOf (Headers ls a) # 
Instance details

Defined in Servant.API.UVerb

type StatusOf (Headers ls a) = StatusOf a
type StatusOf (WithStatus n a) # 
Instance details

Defined in Servant.API.UVerb

type StatusOf (WithStatus n a) = n

type family Statuses (as :: [Type]) :: [Nat] #

Instances

Instances details
type Statuses ('[] :: [Type]) # 
Instance details

Defined in Servant.API.UVerb

type Statuses ('[] :: [Type]) = '[] :: [Nat]
type Statuses (a ': as) # 
Instance details

Defined in Servant.API.UVerb

type Statuses (a ': as) = StatusOf a ': Statuses as

type family Statuses (as :: [Type]) :: [Nat] #

Instances

Instances details
type Statuses ('[] :: [Type]) # 
Instance details

Defined in Servant.API.UVerb

type Statuses ('[] :: [Type]) = '[] :: [Nat]
type Statuses (a ': as) # 
Instance details

Defined in Servant.API.UVerb

type Statuses (a ': as) = StatusOf a ': Statuses as

newtype WithStatus (k :: Nat) a #

A simple newtype wrapper that pairs a type with its status code. It implements all the content types that Servant ships with by default.

Constructors

WithStatus a 

Instances

Instances details
MimeRender FormUrlEncoded a => MimeRender FormUrlEncoded (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeRender JSON a => MimeRender JSON (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

Methods

mimeRender :: Proxy JSON -> WithStatus _status a -> ByteString #

MimeRender OctetStream a => MimeRender OctetStream (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeRender PlainText a => MimeRender PlainText (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

Methods

mimeRender :: Proxy PlainText -> WithStatus _status a -> ByteString #

MimeUnrender FormUrlEncoded a => MimeUnrender FormUrlEncoded (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeUnrender JSON a => MimeUnrender JSON (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeUnrender OctetStream a => MimeUnrender OctetStream (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeUnrender PlainText a => MimeUnrender PlainText (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

Show a => Show (WithStatus k a) # 
Instance details

Defined in Servant.API.UVerb

Methods

showsPrec :: Int -> WithStatus k a -> ShowS #

show :: WithStatus k a -> String #

showList :: [WithStatus k a] -> ShowS #

Eq a => Eq (WithStatus k a) # 
Instance details

Defined in Servant.API.UVerb

Methods

(==) :: WithStatus k a -> WithStatus k a -> Bool #

(/=) :: WithStatus k a -> WithStatus k a -> Bool #

KnownStatus n => HasStatus (WithStatus n a) #

an instance of this typeclass assigns a HTTP status code to a return type

Example:

   data NotFoundError = NotFoundError String

   instance HasStatus NotFoundError where
     type StatusOf NotFoundError = 404

You can also use the convience newtype wrapper WithStatus if you want to avoid writing a HasStatus instance manually. It also has the benefit of showing the status code in the type; which might aid in readability.

Instance details

Defined in Servant.API.UVerb

Associated Types

type StatusOf (WithStatus n a) 
Instance details

Defined in Servant.API.UVerb

type StatusOf (WithStatus n a) = n
type StatusOf (WithStatus n a) # 
Instance details

Defined in Servant.API.UVerb

type StatusOf (WithStatus n a) = n

inject :: UElem x xs => f x -> NS f xs #

statusOf :: HasStatus a => proxy a -> Status #

Sub-APIs defined as records of routes

class GenericMode mode #

A class with a type family that applies an appropriate type family to the api parameter. For example, AsApi will leave api untouched, while AsServerT m will produce ServerT api m.

Associated Types

type mode :- api infixl 0 #

Instances

Instances details
GenericMode AsApi # 
Instance details

Defined in Servant.API.Generic

Associated Types

type AsApi :- api 
Instance details

Defined in Servant.API.Generic

type AsApi :- api = api
GenericMode (AsLink a) # 
Instance details

Defined in Servant.Links

type family mode :- api infixl 0 #

Instances

Instances details
type AsApi :- api # 
Instance details

Defined in Servant.API.Generic

type AsApi :- api = api
type (AsLink a) :- api # 
Instance details

Defined in Servant.Links

type (AsLink a) :- api = MkLink api a

data AsApi #

A type that specifies that an API record contains an API definition. Only useful at type-level.

Instances

Instances details
GenericMode AsApi # 
Instance details

Defined in Servant.API.Generic

Associated Types

type AsApi :- api 
Instance details

Defined in Servant.API.Generic

type AsApi :- api = api
type AsApi :- api # 
Instance details

Defined in Servant.API.Generic

type AsApi :- api = api

class GServantProduct (f :: Type -> Type) #

Minimal complete definition

gtoServant, gfromServant

Instances

Instances details
(GServantProduct l, GServantProduct r) => GServantProduct (l :*: r) # 
Instance details

Defined in Servant.API.Generic

Methods

gtoServant :: (l :*: r) p -> GToServant (l :*: r)

gfromServant :: GToServant (l :*: r) -> (l :*: r) p

GServantProduct (K1 i c :: Type -> Type) # 
Instance details

Defined in Servant.API.Generic

Methods

gtoServant :: K1 i c p -> GToServant (K1 i c :: Type -> Type)

gfromServant :: GToServant (K1 i c :: Type -> Type) -> K1 i c p

GServantProduct f => GServantProduct (M1 i c f) # 
Instance details

Defined in Servant.API.Generic

Methods

gtoServant :: M1 i c f p -> GToServant (M1 i c f)

gfromServant :: GToServant (M1 i c f) -> M1 i c f p

type GenericServant (routes :: Type -> Type) mode = (GenericMode mode, Generic (routes mode), GServantProduct (Rep (routes mode))) #

A constraint alias, for work with mode and routes.

type ToServant (routes :: Type -> Type) mode = GToServant (Rep (routes mode)) #

Turns a generic product type into a tree of :<|> combinators.

type ToServantApi (routes :: Type -> Type) = ToServant routes AsApi #

fromServant :: GenericServant routes mode => ToServant routes mode -> routes mode #

Inverse of toServant.

This can be used to turn generated values such as client functions into records.

You may need to provide a type signature for the output type (your record type).

genericApi :: forall (routes :: Type -> Type). GenericServant routes AsApi => Proxy routes -> Proxy (ToServantApi routes) #

Get a Proxy of an API type.

toServant :: GenericServant routes mode => routes mode -> ToServant routes mode #

See ToServant, but at value-level.

Streaming endpoints, distinguished by HTTP method

data Stream (method :: k1) (status :: Nat) framing contentType a #

A Stream endpoint for a given method emits a stream of encoded values at a given Content-Type, delimited by a framing strategy. Type synonyms are provided for standard methods.

Instances

Instances details
HasLink (Stream m status fr ct a :: Type) # 
Instance details

Defined in Servant.Links

Methods

toLink :: (Link -> a0) -> Proxy (Stream m status fr ct a) -> Link -> MkLink (Stream m status fr ct a) a0 #

Generic (Stream method status framing contentType a) # 
Instance details

Defined in Servant.API.Stream

Associated Types

type Rep (Stream method status framing contentType a) 
Instance details

Defined in Servant.API.Stream

type Rep (Stream method status framing contentType a) = D1 ('MetaData "Stream" "Servant.API.Stream" "servant-0.20.1-DlxSeFXhWhX4WccYlHDTNj" 'False) (V1 :: Type -> Type)

Methods

from :: Stream method status framing contentType a -> Rep (Stream method status framing contentType a) x #

to :: Rep (Stream method status framing contentType a) x -> Stream method status framing contentType a #

type MkLink (Stream m status fr ct a :: Type) r # 
Instance details

Defined in Servant.Links

type MkLink (Stream m status fr ct a :: Type) r = r
type Rep (Stream method status framing contentType a) # 
Instance details

Defined in Servant.API.Stream

type Rep (Stream method status framing contentType a) = D1 ('MetaData "Stream" "Servant.API.Stream" "servant-0.20.1-DlxSeFXhWhX4WccYlHDTNj" 'False) (V1 :: Type -> Type)

class FramingRender (strategy :: k) where #

The FramingRender class provides the logic for emitting a framing strategy. The strategy transforms a SourceT m a into SourceT m ByteString, therefore it can prepend, append and intercalate framing structure around chunks.

Note: as the Monad m is generic, this is pure transformation.

Methods

framingRender :: forall (m :: Type -> Type) a. Monad m => Proxy strategy -> (a -> ByteString) -> SourceT m a -> SourceT m ByteString #

Instances

Instances details
FramingRender NetstringFraming # 
Instance details

Defined in Servant.API.Stream

Methods

framingRender :: forall (m :: Type -> Type) a. Monad m => Proxy NetstringFraming -> (a -> ByteString) -> SourceT m a -> SourceT m ByteString #

FramingRender NewlineFraming # 
Instance details

Defined in Servant.API.Stream

Methods

framingRender :: forall (m :: Type -> Type) a. Monad m => Proxy NewlineFraming -> (a -> ByteString) -> SourceT m a -> SourceT m ByteString #

FramingRender NoFraming # 
Instance details

Defined in Servant.API.Stream

Methods

framingRender :: forall (m :: Type -> Type) a. Monad m => Proxy NoFraming -> (a -> ByteString) -> SourceT m a -> SourceT m ByteString #

class FramingUnrender (strategy :: k) where #

The FramingUnrender class provides the logic for parsing a framing strategy.

Methods

framingUnrender :: forall (m :: Type -> Type) a. Monad m => Proxy strategy -> (ByteString -> Either String a) -> SourceT m ByteString -> SourceT m a #

Instances

Instances details
FramingUnrender NetstringFraming # 
Instance details

Defined in Servant.API.Stream

Methods

framingUnrender :: forall (m :: Type -> Type) a. Monad m => Proxy NetstringFraming -> (ByteString -> Either String a) -> SourceT m ByteString -> SourceT m a #

FramingUnrender NewlineFraming # 
Instance details

Defined in Servant.API.Stream

Methods

framingUnrender :: forall (m :: Type -> Type) a. Monad m => Proxy NewlineFraming -> (ByteString -> Either String a) -> SourceT m ByteString -> SourceT m a #

FramingUnrender NoFraming #

As NoFraming doesn't have frame separators, we take the chunks as given and try to convert them one by one.

That works well when a is a ByteString.

Instance details

Defined in Servant.API.Stream

Methods

framingUnrender :: forall (m :: Type -> Type) a. Monad m => Proxy NoFraming -> (ByteString -> Either String a) -> SourceT m ByteString -> SourceT m a #

class FromSourceIO chunk a | a -> chunk where #

FromSourceIO is intended to be implemented for types such as Conduit, Pipe, etc. By implementing this class, all such streaming abstractions can be used directly on the client side for talking to streaming endpoints.

Methods

fromSourceIO :: SourceIO chunk -> IO a #

Instances

Instances details
MonadIO m => FromSourceIO a (SourceT m a) # 
Instance details

Defined in Servant.API.Stream

Methods

fromSourceIO :: SourceIO a -> IO (SourceT m a) #

data NetstringFraming #

The netstring framing strategy as defined by djb: http://cr.yp.to/proto/netstrings.txt

Any string of 8-bit bytes may be encoded as [len]":"[string]",". Here [string] is the string and [len] is a nonempty sequence of ASCII digits giving the length of [string] in decimal. The ASCII digits are 30 for 0, 31 for 1, and so on up through 39 for 9. Extra zeros at the front of [len] are prohibited: [len] begins with 30 exactly when [string] is empty.

For example, the string "hello world!" is encoded as 32 3a 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 2c, i.e., "12:hello world!,". The empty string is encoded as "0:,".

Instances

Instances details
FramingRender NetstringFraming # 
Instance details

Defined in Servant.API.Stream

Methods

framingRender :: forall (m :: Type -> Type) a. Monad m => Proxy NetstringFraming -> (a -> ByteString) -> SourceT m a -> SourceT m ByteString #

FramingUnrender NetstringFraming # 
Instance details

Defined in Servant.API.Stream

Methods

framingUnrender :: forall (m :: Type -> Type) a. Monad m => Proxy NetstringFraming -> (ByteString -> Either String a) -> SourceT m ByteString -> SourceT m a #

data NewlineFraming #

A simple framing strategy that has no header, and inserts a newline character after each frame. This assumes that it is used with a Content-Type that encodes without newlines (e.g. JSON).

Instances

Instances details
FramingRender NewlineFraming # 
Instance details

Defined in Servant.API.Stream

Methods

framingRender :: forall (m :: Type -> Type) a. Monad m => Proxy NewlineFraming -> (a -> ByteString) -> SourceT m a -> SourceT m ByteString #

FramingUnrender NewlineFraming # 
Instance details

Defined in Servant.API.Stream

Methods

framingUnrender :: forall (m :: Type -> Type) a. Monad m => Proxy NewlineFraming -> (ByteString -> Either String a) -> SourceT m ByteString -> SourceT m a #

data NoFraming #

A framing strategy that does not do any framing at all, it just passes the input data This will be used most of the time with binary data, such as files

Instances

Instances details
FramingRender NoFraming # 
Instance details

Defined in Servant.API.Stream

Methods

framingRender :: forall (m :: Type -> Type) a. Monad m => Proxy NoFraming -> (a -> ByteString) -> SourceT m a -> SourceT m ByteString #

FramingUnrender NoFraming #

As NoFraming doesn't have frame separators, we take the chunks as given and try to convert them one by one.

That works well when a is a ByteString.

Instance details

Defined in Servant.API.Stream

Methods

framingUnrender :: forall (m :: Type -> Type) a. Monad m => Proxy NoFraming -> (ByteString -> Either String a) -> SourceT m ByteString -> SourceT m a #

type SourceIO = SourceT IO #

Stream endpoints may be implemented as producing a SourceIO chunk.

Clients reading from streaming endpoints can be implemented as consuming a SourceIO chunk.

type StreamBody = StreamBody' ('[] :: [Type]) #

A stream request body.

data StreamBody' (mods :: [Type]) framing contentType a #

Instances

Instances details
HasLink sub => HasLink (StreamBody' mods framing ct a :> sub :: Type) # 
Instance details

Defined in Servant.Links

Methods

toLink :: (Link -> a0) -> Proxy (StreamBody' mods framing ct a :> sub) -> Link -> MkLink (StreamBody' mods framing ct a :> sub) a0 #

Generic (StreamBody' mods framing contentType a) # 
Instance details

Defined in Servant.API.Stream

Associated Types

type Rep (StreamBody' mods framing contentType a) 
Instance details

Defined in Servant.API.Stream

type Rep (StreamBody' mods framing contentType a) = D1 ('MetaData "StreamBody'" "Servant.API.Stream" "servant-0.20.1-DlxSeFXhWhX4WccYlHDTNj" 'False) (V1 :: Type -> Type)

Methods

from :: StreamBody' mods framing contentType a -> Rep (StreamBody' mods framing contentType a) x #

to :: Rep (StreamBody' mods framing contentType a) x -> StreamBody' mods framing contentType a #

type MkLink (StreamBody' mods framing ct a :> sub :: Type) r # 
Instance details

Defined in Servant.Links

type MkLink (StreamBody' mods framing ct a :> sub :: Type) r = MkLink sub r
type Rep (StreamBody' mods framing contentType a) # 
Instance details

Defined in Servant.API.Stream

type Rep (StreamBody' mods framing contentType a) = D1 ('MetaData "StreamBody'" "Servant.API.Stream" "servant-0.20.1-DlxSeFXhWhX4WccYlHDTNj" 'False) (V1 :: Type -> Type)

type StreamGet = Stream 'GET 200 #

type StreamPost = Stream 'POST 200 #

class ToSourceIO chunk a | a -> chunk where #

ToSourceIO is intended to be implemented for types such as Conduit, Pipe, etc. By implementing this class, all such streaming abstractions can be used directly as endpoints.

Methods

toSourceIO :: a -> SourceIO chunk #

Instances

Instances details
ToSourceIO a (NonEmpty a) # 
Instance details

Defined in Servant.API.Stream

Methods

toSourceIO :: NonEmpty a -> SourceIO a #

ToSourceIO a [a] # 
Instance details

Defined in Servant.API.Stream

Methods

toSourceIO :: [a] -> SourceIO a #

SourceToSourceIO m => ToSourceIO chunk (SourceT m chunk) #

Relax to use auxiliary class, have m

Instance details

Defined in Servant.API.Stream

Methods

toSourceIO :: SourceT m chunk -> SourceIO chunk #

Authentication

Endpoints description

data Description (sym :: Symbol) #

Add more verbose description for (part of) API.

Example:

>>> :{
type MyApi = Description
 "This comment is visible in multiple Servant interpretations \
 \and can be really long if necessary. \
 \Haskell multiline String support is not perfect \
 \but it's still very readable."
:> Get '[JSON] Book
:}

Instances

Instances details
HasLink sub => HasLink (Description s :> sub :: Type) # 
Instance details

Defined in Servant.Links

Methods

toLink :: (Link -> a) -> Proxy (Description s :> sub) -> Link -> MkLink (Description s :> sub) a #

type MkLink (Description s :> sub :: Type) a # 
Instance details

Defined in Servant.Links

type MkLink (Description s :> sub :: Type) a = MkLink sub a

data Summary (sym :: Symbol) #

Add a short summary for (part of) API.

Example:

>>> type MyApi = Summary "Get book by ISBN." :> "books" :> Capture "isbn" Text :> Get '[JSON] Book

Instances

Instances details
HasLink sub => HasLink (Summary s :> sub :: Type) # 
Instance details

Defined in Servant.Links

Methods

toLink :: (Link -> a) -> Proxy (Summary s :> sub) -> Link -> MkLink (Summary s :> sub) a #

type MkLink (Summary s :> sub :: Type) a # 
Instance details

Defined in Servant.Links

type MkLink (Summary s :> sub :: Type) a = MkLink sub a

Content Types

class Accept (ctype :: k) where #

Instances of Accept represent mimetypes. They are used for matching against the Accept HTTP header of the request, and for setting the Content-Type header of the response

Example:

>>> import Network.HTTP.Media ((//), (/:))
>>> data HTML
>>> :{
instance Accept HTML where
   contentType _ = "text" // "html" /: ("charset", "utf-8")
:}

Minimal complete definition

contentType | contentTypes

Instances

Instances details
Accept FormUrlEncoded #
application/x-www-form-urlencoded
Instance details

Defined in Servant.API.ContentTypes

Accept JSON #
application/json
Instance details

Defined in Servant.API.ContentTypes

Accept OctetStream #
application/octet-stream
Instance details

Defined in Servant.API.ContentTypes

Accept PlainText #
text/plain;charset=utf-8
Instance details

Defined in Servant.API.ContentTypes

data FormUrlEncoded #

Instances

Instances details
Accept FormUrlEncoded #
application/x-www-form-urlencoded
Instance details

Defined in Servant.API.ContentTypes

ToForm a => MimeRender FormUrlEncoded a #

urlEncodeAsForm Note that the mimeUnrender p (mimeRender p x) == Right x law only holds if every element of x is non-null (i.e., not ("", ""))

Instance details

Defined in Servant.API.ContentTypes

FromForm a => MimeUnrender FormUrlEncoded a #

urlDecodeAsForm Note that the mimeUnrender p (mimeRender p x) == Right x law only holds if every element of x is non-null (i.e., not ("", ""))

Instance details

Defined in Servant.API.ContentTypes

MimeRender FormUrlEncoded a => MimeRender FormUrlEncoded (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeUnrender FormUrlEncoded a => MimeUnrender FormUrlEncoded (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

data JSON #

Instances

Instances details
Accept JSON #
application/json
Instance details

Defined in Servant.API.ContentTypes

ToJSON a => MimeRender JSON a #

encode

Instance details

Defined in Servant.API.ContentTypes

Methods

mimeRender :: Proxy JSON -> a -> ByteString #

FromJSON a => MimeUnrender JSON a #

eitherDecode

Instance details

Defined in Servant.API.ContentTypes

MimeRender JSON a => MimeRender JSON (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

Methods

mimeRender :: Proxy JSON -> WithStatus _status a -> ByteString #

MimeUnrender JSON a => MimeUnrender JSON (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

class Accept ctype => MimeRender (ctype :: k) a where #

Instantiate this class to register a way of serializing a type based on the Accept header.

Example:

data MyContentType

instance Accept MyContentType where
   contentType _ = "example" // "prs.me.mine" /: ("charset", "utf-8")

instance Show a => MimeRender MyContentType a where
   mimeRender _ val = pack ("This is MINE! " ++ show val)

type MyAPI = "path" :> Get '[MyContentType] Int

Methods

mimeRender :: Proxy ctype -> a -> ByteString #

Instances

Instances details
ToForm a => MimeRender FormUrlEncoded a #

urlEncodeAsForm Note that the mimeUnrender p (mimeRender p x) == Right x law only holds if every element of x is non-null (i.e., not ("", ""))

Instance details

Defined in Servant.API.ContentTypes

ToJSON a => MimeRender JSON a #

encode

Instance details

Defined in Servant.API.ContentTypes

Methods

mimeRender :: Proxy JSON -> a -> ByteString #

MimeRender OctetStream ByteString #

fromStrict

Instance details

Defined in Servant.API.ContentTypes

MimeRender OctetStream ByteString #
id
Instance details

Defined in Servant.API.ContentTypes

MimeRender PlainText Text #
fromStrict . TextS.encodeUtf8
Instance details

Defined in Servant.API.ContentTypes

MimeRender PlainText Text #

encodeUtf8

Instance details

Defined in Servant.API.ContentTypes

MimeRender PlainText String #
BC.pack
Instance details

Defined in Servant.API.ContentTypes

MimeRender FormUrlEncoded a => MimeRender FormUrlEncoded (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeRender JSON a => MimeRender JSON (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

Methods

mimeRender :: Proxy JSON -> WithStatus _status a -> ByteString #

MimeRender OctetStream a => MimeRender OctetStream (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeRender PlainText a => MimeRender PlainText (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

Methods

mimeRender :: Proxy PlainText -> WithStatus _status a -> ByteString #

class Accept ctype => MimeUnrender (ctype :: k) a where #

Instantiate this class to register a way of deserializing a type based on the request's Content-Type header.

>>> import Network.HTTP.Media hiding (Accept)
>>> import qualified Data.ByteString.Lazy.Char8 as BSC
>>> data MyContentType = MyContentType String
>>> :{
instance Accept MyContentType where
   contentType _ = "example" // "prs.me.mine" /: ("charset", "utf-8")
:}
>>> :{
instance Read a => MimeUnrender MyContentType a where
   mimeUnrender _ bs = case BSC.take 12 bs of
     "MyContentType" -> return . read . BSC.unpack $ BSC.drop 12 bs
     _ -> Left "didn't start with the magic incantation"
:}
>>> type MyAPI = "path" :> ReqBody '[MyContentType] Int :> Get '[JSON] Int

Minimal complete definition

mimeUnrender | mimeUnrenderWithType

Methods

mimeUnrender :: Proxy ctype -> ByteString -> Either String a #

mimeUnrenderWithType :: Proxy ctype -> MediaType -> ByteString -> Either String a #

Variant which is given the actual MediaType provided by the other party.

In the most cases you don't want to branch based on the MediaType. See pr552 for a motivating example.

Instances

Instances details
FromForm a => MimeUnrender FormUrlEncoded a #

urlDecodeAsForm Note that the mimeUnrender p (mimeRender p x) == Right x law only holds if every element of x is non-null (i.e., not ("", ""))

Instance details

Defined in Servant.API.ContentTypes

FromJSON a => MimeUnrender JSON a #

eitherDecode

Instance details

Defined in Servant.API.ContentTypes

MimeUnrender OctetStream ByteString #
Right . toStrict
Instance details

Defined in Servant.API.ContentTypes

MimeUnrender OctetStream ByteString #
Right . id
Instance details

Defined in Servant.API.ContentTypes

MimeUnrender PlainText Text #
left show . TextS.decodeUtf8' . toStrict
Instance details

Defined in Servant.API.ContentTypes

MimeUnrender PlainText Text #
left show . TextL.decodeUtf8'
Instance details

Defined in Servant.API.ContentTypes

MimeUnrender PlainText String #
Right . BC.unpack
Instance details

Defined in Servant.API.ContentTypes

MimeUnrender FormUrlEncoded a => MimeUnrender FormUrlEncoded (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeUnrender JSON a => MimeUnrender JSON (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeUnrender OctetStream a => MimeUnrender OctetStream (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeUnrender PlainText a => MimeUnrender PlainText (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

data NoContent #

A type for responses without content-body.

Constructors

NoContent 

Instances

Instances details
Generic NoContent # 
Instance details

Defined in Servant.API.ContentTypes

Associated Types

type Rep NoContent 
Instance details

Defined in Servant.API.ContentTypes

type Rep NoContent = D1 ('MetaData "NoContent" "Servant.API.ContentTypes" "servant-0.20.1-DlxSeFXhWhX4WccYlHDTNj" 'False) (C1 ('MetaCons "NoContent" 'PrefixI 'False) (U1 :: Type -> Type))
Read NoContent # 
Instance details

Defined in Servant.API.ContentTypes

Show NoContent # 
Instance details

Defined in Servant.API.ContentTypes

NFData NoContent # 
Instance details

Defined in Servant.API.ContentTypes

Methods

rnf :: NoContent -> () #

Eq NoContent # 
Instance details

Defined in Servant.API.ContentTypes

HasStatus NoContent #

If an API can respond with NoContent we assume that this will happen with the status code 204 No Content. If this needs to be overridden, WithStatus can be used.

Instance details

Defined in Servant.API.UVerb

Associated Types

type StatusOf NoContent 
Instance details

Defined in Servant.API.UVerb

type StatusOf NoContent = 204
AllMime (ctyp ': (ctyp' ': ctyps)) => AllMimeRender (ctyp ': (ctyp' ': ctyps)) NoContent # 
Instance details

Defined in Servant.API.ContentTypes

Methods

allMimeRender :: Proxy (ctyp ': (ctyp' ': ctyps)) -> NoContent -> [(MediaType, ByteString)] #

Accept ctyp => AllMimeRender '[ctyp] NoContent # 
Instance details

Defined in Servant.API.ContentTypes

Methods

allMimeRender :: Proxy '[ctyp] -> NoContent -> [(MediaType, ByteString)] #

type Rep NoContent # 
Instance details

Defined in Servant.API.ContentTypes

type Rep NoContent = D1 ('MetaData "NoContent" "Servant.API.ContentTypes" "servant-0.20.1-DlxSeFXhWhX4WccYlHDTNj" 'False) (C1 ('MetaCons "NoContent" 'PrefixI 'False) (U1 :: Type -> Type))
type StatusOf NoContent # 
Instance details

Defined in Servant.API.UVerb

type StatusOf NoContent = 204

data OctetStream #

Instances

Instances details
Accept OctetStream #
application/octet-stream
Instance details

Defined in Servant.API.ContentTypes

MimeRender OctetStream ByteString #

fromStrict

Instance details

Defined in Servant.API.ContentTypes

MimeRender OctetStream ByteString #
id
Instance details

Defined in Servant.API.ContentTypes

MimeUnrender OctetStream ByteString #
Right . toStrict
Instance details

Defined in Servant.API.ContentTypes

MimeUnrender OctetStream ByteString #
Right . id
Instance details

Defined in Servant.API.ContentTypes

MimeRender OctetStream a => MimeRender OctetStream (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

MimeUnrender OctetStream a => MimeUnrender OctetStream (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

data PlainText #

Instances

Instances details
Accept PlainText #
text/plain;charset=utf-8
Instance details

Defined in Servant.API.ContentTypes

MimeRender PlainText Text #
fromStrict . TextS.encodeUtf8
Instance details

Defined in Servant.API.ContentTypes

MimeRender PlainText Text #

encodeUtf8

Instance details

Defined in Servant.API.ContentTypes

MimeRender PlainText String #
BC.pack
Instance details

Defined in Servant.API.ContentTypes

MimeUnrender PlainText Text #
left show . TextS.decodeUtf8' . toStrict
Instance details

Defined in Servant.API.ContentTypes

MimeUnrender PlainText Text #
left show . TextL.decodeUtf8'
Instance details

Defined in Servant.API.ContentTypes

MimeUnrender PlainText String #
Right . BC.unpack
Instance details

Defined in Servant.API.ContentTypes

MimeRender PlainText a => MimeRender PlainText (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

Methods

mimeRender :: Proxy PlainText -> WithStatus _status a -> ByteString #

MimeUnrender PlainText a => MimeUnrender PlainText (WithStatus _status a) # 
Instance details

Defined in Servant.API.UVerb

Serializing and deserializing types based on Accept and Content-Type headers.

Response Headers

data ResponseHeader (sym :: Symbol) a #

Instances

Instances details
Functor (ResponseHeader sym) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

fmap :: (a -> b) -> ResponseHeader sym a -> ResponseHeader sym b #

(<$) :: a -> ResponseHeader sym b -> ResponseHeader sym a #

Show a => Show (ResponseHeader sym a) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

showsPrec :: Int -> ResponseHeader sym a -> ShowS #

show :: ResponseHeader sym a -> String #

showList :: [ResponseHeader sym a] -> ShowS #

NFData a => NFData (ResponseHeader sym a) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

rnf :: ResponseHeader sym a -> () #

Eq a => Eq (ResponseHeader sym a) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

(==) :: ResponseHeader sym a -> ResponseHeader sym a -> Bool #

(/=) :: ResponseHeader sym a -> ResponseHeader sym a -> Bool #

class AddHeader (h :: Symbol) v orig new | h v orig -> new, new -> h, new -> v, new -> orig #

Minimal complete definition

addOptionalHeader

Instances

Instances details
(KnownSymbol h, ToHttpApiData v, new ~ Headers '[Header h v] a) => AddHeader h v a new # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

addOptionalHeader :: ResponseHeader h v -> a -> new

(AddHeader h v old new, AddHeader h v (Union oldrest) (Union newrest), oldrest ~ (a ': as), newrest ~ (b ': bs)) => AddHeader h v (Union (old ': (a ': as))) (Union (new ': (b ': bs))) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

addOptionalHeader :: ResponseHeader h v -> Union (old ': (a ': as)) -> Union (new ': (b ': bs))

AddHeader h v old new => AddHeader h v (Union '[old]) (Union '[new]) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

addOptionalHeader :: ResponseHeader h v -> Union '[old] -> Union '[new]

(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a

class BuildHeadersTo (hs :: [Type]) where #

Methods

buildHeadersTo :: [Header] -> HList hs #

Instances

Instances details
BuildHeadersTo ('[] :: [Type]) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

buildHeadersTo :: [Header] -> HList ('[] :: [Type]) #

(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header h v ': xs) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

buildHeadersTo :: [Header] -> HList (Header h v ': xs) #

class GetHeaders ls where #

Methods

getHeaders :: ls -> [Header] #

Instances

Instances details
GetHeadersFromHList hs => GetHeaders (HList hs) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

getHeaders :: HList hs -> [Header] #

GetHeaders' hs => GetHeaders (Headers hs a) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

getHeaders :: Headers hs a -> [Header] #

data HList (a :: [Type]) where #

Constructors

HNil :: HList ('[] :: [Type]) 
HCons :: forall (h :: Symbol) x (xs :: [Type]). ResponseHeader h x -> HList xs -> HList (Header h x ': xs) 

Instances

Instances details
NFDataHList xs => NFData (HList xs) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

rnf :: HList xs -> () #

GetHeadersFromHList hs => GetHeaders (HList hs) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

getHeaders :: HList hs -> [Header] #

class HasResponseHeader (h :: Symbol) a (headers :: [Type]) #

Minimal complete definition

hlistLookupHeader

Instances

Instances details
HasResponseHeader h a (Header h a ': rest) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

hlistLookupHeader :: HList (Header h a ': rest) -> ResponseHeader h a

HasResponseHeader h a rest => HasResponseHeader h a (first ': rest) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

hlistLookupHeader :: HList (first ': rest) -> ResponseHeader h a

data Headers (ls :: [Type]) a #

Response Header objects. You should never need to construct one directly. Instead, use addOptionalHeader.

Constructors

Headers 

Fields

Instances

Instances details
(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a

Functor (Headers ls) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

fmap :: (a -> b) -> Headers ls a -> Headers ls b #

(<$) :: a -> Headers ls b -> Headers ls a #

(NFDataHList ls, NFData a) => NFData (Headers ls a) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

rnf :: Headers ls a -> () #

GetHeaders' hs => GetHeaders (Headers hs a) # 
Instance details

Defined in Servant.API.ResponseHeaders

Methods

getHeaders :: Headers hs a -> [Header] #

HasStatus a => HasStatus (Headers ls a) # 
Instance details

Defined in Servant.API.UVerb

Associated Types

type StatusOf (Headers ls a) 
Instance details

Defined in Servant.API.UVerb

type StatusOf (Headers ls a) = StatusOf a
type StatusOf (Headers ls a) # 
Instance details

Defined in Servant.API.UVerb

type StatusOf (Headers ls a) = StatusOf a

addHeader :: forall (h :: Symbol) v orig new. AddHeader h v orig new => v -> orig -> new #

addHeader adds a header to a response. Note that it changes the type of the value in the following ways:

  1. A simple value is wrapped in "Headers '[hdr]":
>>> let example0 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] String;
>>> getHeaders example0
[("someheader","5")]
  1. A value that already has a header has its new header *prepended* to the existing list:
>>> let example1 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] String;
>>> let example2 = addHeader True example1 :: Headers '[Header "1st" Bool, Header "someheader" Int] String
>>> getHeaders example2
[("1st","true"),("someheader","5")]

Note that while in your handlers type annotations are not required, since the type can be inferred from the API type, in other cases you may find yourself needing to add annotations.

lookupResponseHeader :: forall (h :: Symbol) a (headers :: [Type]) r. HasResponseHeader h a headers => Headers headers r -> ResponseHeader h a #

Look up a specific ResponseHeader, without having to know what position it is in the HList.

>>> let example1 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] String
>>> let example2 = addHeader True example1 :: Headers '[Header "1st" Bool, Header "someheader" Int] String
>>> lookupResponseHeader example2 :: ResponseHeader "someheader" Int
Header 5
>>> lookupResponseHeader example2 :: ResponseHeader "1st" Bool
Header True

Usage of this function relies on an explicit type annotation of the header to be looked up. This can be done with type annotations on the result, or with an explicit type application. In this example, the type of header value is determined by the type-inference, we only specify the name of the header:

>>> :set -XTypeApplications
>>> case lookupResponseHeader @"1st" example2 of { Header b -> b ; _ -> False }
True

Since: 0.15

noHeader :: forall (h :: Symbol) v orig new. AddHeader h v orig new => orig -> new #

Deliberately do not add a header to a value.

>>> let example1 = noHeader "hi" :: Headers '[Header "someheader" Int] String
>>> getHeaders example1
[]

Untyped endpoints

Plugging in a wai Application, serving directories

FromHttpApiData and ToHttpApiData

class FromHttpApiData a where #

Parse value from HTTP API data.

WARNING: Do not derive this using DeriveAnyClass as the generated instance will loop indefinitely.

Minimal complete definition

parseUrlPiece | parseQueryParam

Methods

parseUrlPiece :: Text -> Either Text a #

Parse URL path piece.

parseHeader :: ByteString -> Either Text a #

Parse HTTP header value.

parseQueryParam :: Text -> Either Text a #

Parse query param value.

Instances

Instances details
FromHttpApiData All 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Any 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Version
>>> showVersion <$> parseUrlPiece "1.2.3"
Right "1.2.3"
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Void

Parsing a Void value is always an error, considering Void as a data type with no constructors.

Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Int16 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Int32 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Int64 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Int8 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Word16 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Word32 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Word64 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Word8 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData SetCookie

Note: this instance works correctly for alphanumeric name and value

>>> parseUrlPiece "SESSID=r2t5uvjq435r4q7ib3vtdjq120" :: Either Text SetCookie
Right (SetCookie {setCookieName = "SESSID", setCookieValue = "r2t5uvjq435r4q7ib3vtdjq120", setCookiePath = Nothing, setCookieExpires = Nothing, setCookieMaxAge = Nothing, setCookieDomain = Nothing, setCookieHttpOnly = False, setCookieSecure = False, setCookieSameSite = Nothing})
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Ordering 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Text 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Text 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Day
>>> toGregorian <$> parseUrlPiece "2016-12-01"
Right (2016,12,1)
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Month
>>> parseUrlPiece "2021-01" :: Either Text Month
Right 2021-01
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Quarter
>>> parseUrlPiece "2021-q1" :: Either Text Quarter
Right 2021-Q1
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData QuarterOfYear
>>> parseUrlPiece "q2" :: Either Text QuarterOfYear
Right Q2
>>> parseUrlPiece "Q3" :: Either Text QuarterOfYear
Right Q3
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData DayOfWeek
>>> parseUrlPiece "Monday" :: Either Text DayOfWeek
Right Monday
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData NominalDiffTime 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData UTCTime
>>> parseUrlPiece "2015-10-03T00:14:24Z" :: Either Text UTCTime
Right 2015-10-03 00:14:24 UTC
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData LocalTime
>>> parseUrlPiece "2015-10-03T14:55:01" :: Either Text LocalTime
Right 2015-10-03 14:55:01
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData TimeOfDay
>>> parseUrlPiece "14:55:01.333" :: Either Text TimeOfDay
Right 14:55:01.333
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData ZonedTime
>>> parseUrlPiece "2015-10-03T14:55:01+0000" :: Either Text ZonedTime
Right 2015-10-03 14:55:01 +0000
>>> parseQueryParam "2016-12-31T01:00:00Z" :: Either Text ZonedTime
Right 2016-12-31 01:00:00 +0000
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData UUID 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData String 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Integer 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Natural 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData ()
>>> parseUrlPiece "_" :: Either Text ()
Right ()
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Bool 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Char 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Double 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Float 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Int 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData Word 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Identity a)

Since: http-api-data-0.4.2

Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (First a) 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Last a) 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (First a) 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Last a) 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Max a) 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Min a) 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Dual a) 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Product a) 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Sum a) 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (LenientData a) 
Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Maybe a)
>>> parseUrlPiece "Just 123" :: Either Text (Maybe Int)
Right (Just 123)
Instance details

Defined in Web.Internal.HttpApiData

(FromHttpApiData a, FromHttpApiData b) => FromHttpApiData (Either a b)
>>> parseUrlPiece "Right 123" :: Either Text (Either String Int)
Right (Right 123)
Instance details

Defined in Web.Internal.HttpApiData

HasResolution a => FromHttpApiData (Fixed a)

Note: this instance is not polykinded

Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Const a b)

Since: http-api-data-0.4.2

Instance details

Defined in Web.Internal.HttpApiData

FromHttpApiData a => FromHttpApiData (Tagged b a)

Note: this instance is not polykinded

Instance details

Defined in Web.Internal.HttpApiData

class ToHttpApiData a where #

Convert value to HTTP API data.

WARNING: Do not derive this using DeriveAnyClass as the generated instance will loop indefinitely.

Minimal complete definition

toUrlPiece | toQueryParam

Methods

toUrlPiece :: a -> Text #

Convert to URL path piece.

toEncodedUrlPiece :: a -> Builder #

Convert to a URL path piece, making sure to encode any special chars. The default definition uses urlEncodeBuilder False but this may be overriden with a more efficient version.

toHeader :: a -> ByteString #

Convert to HTTP header value.

toQueryParam :: a -> Text #

Convert to query param value.

toEncodedQueryParam :: a -> Builder #

Convert to URL query param, The default definition uses urlEncodeBuilder True but this may be overriden with a more efficient version.

Since: http-api-data-0.5.1

Instances

Instances details
ToHttpApiData All 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Any 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Version
>>> toUrlPiece (Version [1, 2, 3] [])
"1.2.3"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Void 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Int16 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Int32 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Int64 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Int8 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Word16 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Word32 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Word64 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Word8 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData SetCookie

Note: this instance works correctly for alphanumeric name and value

>>> let Right c = parseUrlPiece "SESSID=r2t5uvjq435r4q7ib3vtdjq120" :: Either Text SetCookie
>>> toUrlPiece c
"SESSID=r2t5uvjq435r4q7ib3vtdjq120"
>>> toHeader c
"SESSID=r2t5uvjq435r4q7ib3vtdjq120"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Ordering 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Link # 
Instance details

Defined in Servant.Links

ToHttpApiData Text 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Text 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Day
>>> toUrlPiece (fromGregorian 2015 10 03)
"2015-10-03"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Month
>>> import Data.Time.Calendar.Month.Compat (Month (..))
>>> MkMonth 24482
2040-03
>>> toUrlPiece $ MkMonth 24482
"2040-03"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Quarter
>>> import Data.Time.Calendar.Quarter.Compat (Quarter (..))
>>> MkQuarter 8040
2010-Q1
>>> toUrlPiece $ MkQuarter 8040
"2010-q1"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData QuarterOfYear
>>> toUrlPiece Q4
"q4"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData DayOfWeek
>>> toUrlPiece Monday
"monday"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData NominalDiffTime 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData UTCTime
>>> toUrlPiece $ UTCTime (fromGregorian 2015 10 03) 864.5
"2015-10-03T00:14:24.500Z"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData LocalTime
>>> toUrlPiece $ LocalTime (fromGregorian 2015 10 03) (TimeOfDay 14 55 21.687)
"2015-10-03T14:55:21.687"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData TimeOfDay
>>> toUrlPiece $ TimeOfDay 14 55 23.1
"14:55:23.100"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData ZonedTime
>>> toUrlPiece $ ZonedTime (LocalTime (fromGregorian 2015 10 03) (TimeOfDay 14 55 51.001)) utc
"2015-10-03T14:55:51.001Z"
>>> toUrlPiece $ ZonedTime (LocalTime (fromGregorian 2015 10 03) (TimeOfDay 14 55 51.001)) (TimeZone 120 True "EET")
"2015-10-03T14:55:51.001+02:00"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData UUID 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData String 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Integer 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Natural 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData ()
>>> toUrlPiece ()
"_"
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Bool 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Char 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Double 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Float 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Int 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Word 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Identity a)

Since: http-api-data-0.4.2

Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (First a) 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Last a) 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (First a) 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Last a) 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Max a) 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Min a) 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Dual a) 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Product a) 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Sum a) 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Maybe a)
>>> toUrlPiece (Just "Hello")
"just Hello"
Instance details

Defined in Web.Internal.HttpApiData

(ToHttpApiData a, ToHttpApiData b) => ToHttpApiData (Either a b)
>>> toUrlPiece (Left "err" :: Either String Int)
"left err"
>>> toUrlPiece (Right 3 :: Either String Int)
"right 3"
Instance details

Defined in Web.Internal.HttpApiData

HasResolution a => ToHttpApiData (Fixed a)

Note: this instance is not polykinded

Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Const a b)

Since: http-api-data-0.4.2

Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData a => ToHttpApiData (Tagged b a)

Note: this instance is not polykinded

Instance details

Defined in Web.Internal.HttpApiData

Classes and instances for types that can be converted to and from HTTP API data.

Experimental modules

General Authentication

Links

data URI #

Represents a general universal resource identifier using its component parts.

For example, for the URI

  foo://anonymous@www.haskell.org:42/ghc?query#frag

the components are:

Constructors

URI 

Fields

Instances

Instances details
FromJSON URI

Since: aeson-2.2.0.0

Instance details

Defined in Data.Aeson.Types.FromJSON

FromJSONKey URI

Since: aeson-2.2.0.0

Instance details

Defined in Data.Aeson.Types.FromJSON

ToJSON URI

Since: aeson-2.2.0.0

Instance details

Defined in Data.Aeson.Types.ToJSON

ToJSONKey URI

Since: aeson-2.2.0.0

Instance details

Defined in Data.Aeson.Types.ToJSON

Data URI 
Instance details

Defined in Network.URI

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> URI -> c URI #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c URI #

toConstr :: URI -> Constr #

dataTypeOf :: URI -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c URI) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c URI) #

gmapT :: (forall b. Data b => b -> b) -> URI -> URI #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> URI -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> URI -> r #

gmapQ :: (forall d. Data d => d -> u) -> URI -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> URI -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> URI -> m URI #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> URI -> m URI #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> URI -> m URI #

Generic URI 
Instance details

Defined in Network.URI

Associated Types

type Rep URI 
Instance details

Defined in Network.URI

Methods

from :: URI -> Rep URI x #

to :: Rep URI x -> URI #

Show URI 
Instance details

Defined in Network.URI

Methods

showsPrec :: Int -> URI -> ShowS #

show :: URI -> String #

showList :: [URI] -> ShowS #

NFData URI 
Instance details

Defined in Network.URI

Methods

rnf :: URI -> () #

Eq URI 
Instance details

Defined in Network.URI

Methods

(==) :: URI -> URI -> Bool #

(/=) :: URI -> URI -> Bool #

Ord URI 
Instance details

Defined in Network.URI

Methods

compare :: URI -> URI -> Ordering #

(<) :: URI -> URI -> Bool #

(<=) :: URI -> URI -> Bool #

(>) :: URI -> URI -> Bool #

(>=) :: URI -> URI -> Bool #

max :: URI -> URI -> URI #

min :: URI -> URI -> URI #

Lift URI 
Instance details

Defined in Network.URI

Methods

lift :: Quote m => URI -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => URI -> Code m URI #

type Rep URI 
Instance details

Defined in Network.URI

class HasLink (endpoint :: k) where #

Construct a toLink for an endpoint.

Associated Types

type MkLink (endpoint :: k) a #

Methods

toLink #

Arguments

:: (Link -> a) 
-> Proxy endpoint

The API endpoint you would like to point to

-> Link 
-> MkLink endpoint a 

Instances

type family IsElem endpoint api where ... #

Closed type family, check if endpoint is within api. Uses IsElem' if it exhausts all other options.

>>> ok (Proxy :: Proxy (IsElem ("hello" :> Get '[JSON] Int) SampleAPI))
OK
>>> ok (Proxy :: Proxy (IsElem ("bye" :> Get '[JSON] Int) SampleAPI))
...
... Could not ...
...

An endpoint is considered within an api even if it is missing combinators that don't affect the URL:

>>> ok (Proxy :: Proxy (IsElem (Get '[JSON] Int) (Header "h" Bool :> Get '[JSON] Int)))
OK
>>> ok (Proxy :: Proxy (IsElem (Get '[JSON] Int) (ReqBody '[JSON] Bool :> Get '[JSON] Int)))
OK
  • N.B.:* IsElem a b can be seen as capturing the notion of whether the URL represented by a would match the URL represented by b, *not* whether a request represented by a matches the endpoints serving b (for the latter, use IsIn).

Equations

IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb) 
IsElem (e :> sa) (e :> sb) = IsElem sa sb 
IsElem sa (Header sym x :> sb) = IsElem sa sb 
IsElem sa (ReqBody y x :> sb) = IsElem sa sb 
IsElem (CaptureAll z y :> sa) (CaptureAll x y :> sb) = IsElem sa sb 
IsElem (Capture z y :> sa) (Capture x y :> sb) = IsElem sa sb 
IsElem sa (QueryParam x y :> sb) = IsElem sa sb 
IsElem sa (QueryParams x y :> sb) = IsElem sa sb 
IsElem sa (QueryFlag x :> sb) = IsElem sa sb 
IsElem sa (Fragment x :> sb) = IsElem sa sb 
IsElem (Verb m s ct typ) (Verb m s ct' typ) = IsSubList ct ct' 
IsElem e e = () 
IsElem e a = IsElem' e a 

type family IsElem' a s #

You may use this type family to tell the type checker that your custom type may be skipped as part of a link. This is useful for things like QueryParam that are optional in a URI and do not affect them if they are omitted.

>>> data CustomThing
>>> type instance IsElem' e (CustomThing :> s) = IsElem e s

Note that IsElem is called, which will mutually recurse back to IsElem' if it exhausts all other options again.

Once you have written a HasLink instance for CustomThing you are ready to go.

data Link #

A safe link datatype. The only way of constructing a Link is using safeLink, which means any Link is guaranteed to be part of the mentioned API.

Instances

safeLink #

Arguments

:: (IsElem endpoint api, HasLink endpoint) 
=> Proxy api

The whole API that this endpoint is a part of

-> Proxy endpoint

The API endpoint you would like to point to

-> MkLink endpoint Link 

Create a valid (by construction) relative URI with query params.

This function will only typecheck if endpoint is part of the API api

type family MkLink (endpoint :: k) a #

Instances

Type-safe internal URIs

Re-exports

type family If (cond :: Bool) (tru :: k) (fls :: k) :: k where ... #

Type-level If. If True a b ==> a; If False a b ==> b

Equations

If 'True (tru :: k) (fls :: k) = tru 
If 'False (tru :: k) (fls :: k) = fls 

data SBool (b :: Bool) where #

Constructors

STrue :: SBool 'True 
SFalse :: SBool 'False 

Instances

Instances details
EqP SBool

Since: singleton-bool-0.1.7

Instance details

Defined in Data.Singletons.Bool

Methods

eqp :: forall (a :: Bool) (b :: Bool). SBool a -> SBool b -> Bool #

GNFData SBool

Since: singleton-bool-0.1.6

Instance details

Defined in Data.Singletons.Bool

Methods

grnf :: forall (a :: Bool). SBool a -> () #

GCompare SBool

Since: singleton-bool-0.1.6

Instance details

Defined in Data.Singletons.Bool

Methods

gcompare :: forall (a :: Bool) (b :: Bool). SBool a -> SBool b -> GOrdering a b #

GEq SBool
>>> geq STrue STrue
Just Refl
>>> geq STrue SFalse
Nothing

Since: singleton-bool-0.1.6

Instance details

Defined in Data.Singletons.Bool

Methods

geq :: forall (a :: Bool) (b :: Bool). SBool a -> SBool b -> Maybe (a :~: b) #

GRead SBool
>>> readsPrec 0 "Some STrue" :: [(Some SBool, String)]
[(Some STrue,"")]
>>> readsPrec 0 "Some SFalse" :: [(Some SBool, String)]
[(Some SFalse,"")]
>>> readsPrec 0 "Some Else" :: [(Some SBool, String)]
[]

Since: singleton-bool-0.1.6

Instance details

Defined in Data.Singletons.Bool

Methods

greadsPrec :: Int -> GReadS SBool #

GShow SBool
>>> showsPrec 0 STrue ""
"STrue"

Since: singleton-bool-0.1.6

Instance details

Defined in Data.Singletons.Bool

Methods

gshowsPrec :: forall (a :: Bool). Int -> SBool a -> ShowS #

OrdP SBool

Since: singleton-bool-0.1.7

Instance details

Defined in Data.Singletons.Bool

Methods

comparep :: forall (a :: Bool) (b :: Bool). SBool a -> SBool b -> Ordering #

Show (SBool b)

Since: singleton-bool-0.1.5

Instance details

Defined in Data.Singletons.Bool

Methods

showsPrec :: Int -> SBool b -> ShowS #

show :: SBool b -> String #

showList :: [SBool b] -> ShowS #

SBoolI b => Boring (SBool b)

Since: singleton-bool-0.1.6

Instance details

Defined in Data.Singletons.Bool

Methods

boring :: SBool b #

NFData (SBool b)

Since: singleton-bool-0.1.6

Instance details

Defined in Data.Singletons.Bool

Methods

rnf :: SBool b -> () #

Eq (SBool b)

Since: singleton-bool-0.1.5

Instance details

Defined in Data.Singletons.Bool

Methods

(==) :: SBool b -> SBool b -> Bool #

(/=) :: SBool b -> SBool b -> Bool #

Ord (SBool b)

Since: singleton-bool-0.1.5

Instance details

Defined in Data.Singletons.Bool

Methods

compare :: SBool b -> SBool b -> Ordering #

(<) :: SBool b -> SBool b -> Bool #

(<=) :: SBool b -> SBool b -> Bool #

(>) :: SBool b -> SBool b -> Bool #

(>=) :: SBool b -> SBool b -> Bool #

max :: SBool b -> SBool b -> SBool b #

min :: SBool b -> SBool b -> SBool b #

class SBoolI (b :: Bool) where #

Methods

sbool :: SBool b #

Instances

Instances details
SBoolI 'False 
Instance details

Defined in Data.Singletons.Bool

Methods

sbool :: SBool 'False #

SBoolI 'True 
Instance details

Defined in Data.Singletons.Bool

Methods

sbool :: SBool 'True #