| Copyright | (c) Frederick Pringle 2025 |
|---|---|
| License | BSD-3-Clause |
| Maintainer | freddyjepringle@gmail.com |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Servant.API.Routes.Internal.Response
Description
Internal module, subject to change.
Synopsis
- newtype Responses = Responses {}
- unResponses :: Lens' Responses (Some Response)
- data Response = Response {}
- responseType :: Lens' Response TypeRep
- responseHeaders :: Lens' Response (Set HeaderRep)
- 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 ResponseUVerb.
Note that a Response consists of a return body type, as well as the return headers.
Constructors
| Responses | |
Fields | |
A representation of one possible response that a Servant endpoint can return.
Currently, the only situation in which multiple Responses can be returned
is using the UVerb combinator. This bundles response types together with
response Headers, so we do the same here.
Constructors
| Response | |
Fields | |
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
Responses from a type-level list of types, all of which haveHasResponseinstances. - More impressively, its instances enforce that
getResponseswill only type-check for type-level lists of length 2 or more. This is becauseAllHasResponsewill only ever be used byoneOfResponses, which is the only way to construct aMany@Responseand 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 ofResponses 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 # | |