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

Servant.API.UVerb

Description

An alternative to Verb for end-points that respond with a resource value of any of an open union of types, and specific status codes for each type in this union. (UVerb is short for UnionVerb)

This can be used for returning (rather than throwing) exceptions in a server as in, say '[Report, WaiError]; or responding with either a 303 forward with a location header, or 201 created with a different body type, depending on the circumstances. (All of this can be done with vanilla servant-server by throwing exceptions, but it can't be represented in the API types without something like UVerb.)

See https://docs.servant.dev/en/stable/cookbook/uverb/UVerb.html for a working example.

Synopsis

Documentation

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

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.

class KnownStatus (StatusOf a) => HasStatus (a :: *) Source #

Associated Types

type StatusOf (a :: *) :: Nat Source #

Instances

Instances details
HasStatus NoContent Source #

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 :: Nat Source #

KnownStatus n => HasStatus (WithStatus n a) Source # 
Instance details

Defined in Servant.API.UVerb

Associated Types

type StatusOf (WithStatus n a) :: Nat Source #

statusOf :: forall a proxy. HasStatus a => proxy a -> Status Source #

class HasStatuses (as :: [*]) where Source #

Associated Types

type Statuses (as :: [*]) :: [Nat] Source #

Methods

statuses :: Proxy as -> [Status] Source #

Instances

Instances details
HasStatuses ('[] :: [Type]) Source # 
Instance details

Defined in Servant.API.UVerb

Associated Types

type Statuses '[] :: [Nat] Source #

Methods

statuses :: Proxy '[] -> [Status] Source #

(HasStatus a, HasStatuses as) => HasStatuses (a ': as) Source # 
Instance details

Defined in Servant.API.UVerb

Associated Types

type Statuses (a ': as) :: [Nat] Source #

Methods

statuses :: Proxy (a ': as) -> [Status] Source #

newtype WithStatus (k :: Nat) a Source #

Constructors

WithStatus a 

Instances

Instances details
MimeUnrender ctype a => MimeUnrender (ctype :: Type) (WithStatus _status a) Source # 
Instance details

Defined in Servant.API.UVerb

MimeRender ctype a => MimeRender (ctype :: Type) (WithStatus _status a) Source # 
Instance details

Defined in Servant.API.UVerb

Methods

mimeRender :: Proxy ctype -> WithStatus _status a -> ByteString Source #

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

Defined in Servant.API.UVerb

Methods

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

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

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

Defined in Servant.API.UVerb

Methods

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

show :: WithStatus k a -> String #

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

Generic (WithStatus k a) Source # 
Instance details

Defined in Servant.API.UVerb

Associated Types

type Rep (WithStatus k a) :: Type -> Type #

Methods

from :: WithStatus k a -> Rep (WithStatus k a) x #

to :: Rep (WithStatus k a) x -> WithStatus k a #

(Generic (WithStatus n a), ToJSON a) => ToJSON (WithStatus n a) Source # 
Instance details

Defined in Servant.API.UVerb

(Generic (WithStatus n a), FromJSON a) => FromJSON (WithStatus n a) Source # 
Instance details

Defined in Servant.API.UVerb

KnownStatus n => HasStatus (WithStatus n a) Source # 
Instance details

Defined in Servant.API.UVerb

Associated Types

type StatusOf (WithStatus n a) :: Nat Source #

type Rep (WithStatus k a) Source # 
Instance details

Defined in Servant.API.UVerb

type Rep (WithStatus k a) = D1 ('MetaData "WithStatus" "Servant.API.UVerb" "servant-0.18.1-8AzI7G0HY4mJiHzrohUrBF" 'True) (C1 ('MetaCons "WithStatus" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type StatusOf (WithStatus n a) Source # 
Instance details

Defined in Servant.API.UVerb

type StatusOf (WithStatus n a) = n