Copyright | (c) Frederick Pringle 2025 |
---|---|
License | BSD-3-Clause |
Maintainer | freddyjepringle@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Servant.API.Routes.Response
Description
Term-level representation of the responses that Servant endpoints can return.
Synopsis
- data Responses
- unResponses :: Lens' Responses (Some Response)
- noResponse :: Responses
- oneResponse :: forall a. HasResponse a => Responses
- oneOfResponses :: forall as. AllHasResponse as => Responses
- data Response
- responseType :: Lens' Response TypeRep
- responseHeaders :: Lens' Response (Set HeaderRep)
- responses :: Traversal' Responses Response
- class HasResponse a where
- class AllHasResponse (as :: [Type]) where
- getResponses :: [Response]
Documentation
A representation of the response(s) that a Servant endpoint can return.
Under the hood, Responses
is a
.
This allows for the possibility that an endpoint might return one of several
responses, via Some
Response
UVerb
.
Note that a Response
consists of a return body type, as well as the return headers.
noResponse :: Responses Source #
The endpoint will not return a response.
oneResponse :: forall a. HasResponse a => Responses Source #
There is only one possible response. Equivalent to a single
.ReqBody
_ a
oneOfResponses :: forall as. AllHasResponse as => Responses Source #
The endpoint may return one of multiple multiple (>1) responses.
Equivalent to a UVerb
s with more than one type.
A representation of one possible response that a Servant endpoint can return.
Currently, the only situation in which multiple Response
s can be returned
is using the UVerb
combinator. This bundles response types together with
response Header
s, so we do the same here.
Instances
ToJSON Response Source # | |
Show Response Source # | |
Eq Response Source # | |
Ord Response Source # | |
Defined in Servant.API.Routes.Internal.Response |
class HasResponse a where Source #
Get a term-level response from a type-level argument. This encodes the argument(s)
of a Verb
or UVerb
.
Methods
Instances
Typeable a => HasResponse a Source # | |
Defined in Servant.API.Routes.Internal.Response Methods | |
(HasResponse a, GetHeaderReps hs) => HasResponse (Headers hs a) Source # | |
Defined in Servant.API.Routes.Internal.Response Methods |
class AllHasResponse (as :: [Type]) where Source #
Witness that all members of a type-level list are instances of HasResponse
.
This class does 2 things:
- It lets us get a term-level list of
Response
s from a type-level list of types, all of which haveHasResponse
instances. - More impressively, its instances enforce that
getResponses
will only type-check for type-level lists of length 2 or more. This is becauseAllHasResponse
will only ever be used byoneOfResponses
, which is the only way to construct aMany
@Response
and thus lets us enforce the invariant that its list arguments will always have more than 1 element. This lets us make sure that there's only ever one way to represent a list ofResponse
s usingResponses
.
Of course, someone might import this Internal module and define a
instance. Don't do that.HasResponse
a => AllHasResponse
'[a]
Methods
getResponses :: [Response] Source #
Instances
(HasResponse a, AllHasResponse (b ': (c ': as))) => AllHasResponse (a ': (b ': (c ': as))) Source # | |
Defined in Servant.API.Routes.Internal.Response Methods getResponses :: [Response] Source # | |
(HasResponse a, HasResponse b) => AllHasResponse '[a, b] Source # | |
Defined in Servant.API.Routes.Internal.Response Methods getResponses :: [Response] Source # |