servant-routes-0.1.0.0: Generate route descriptions from Servant APIs
Copyright(c) Frederick Pringle 2025
LicenseBSD-3-Clause
Maintainerfreddyjepringle@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Servant.API.Routes.Response

Description

Term-level representation of the responses that Servant endpoints can return.

Synopsis

Documentation

data Responses Source #

A representation of the response(s) that a Servant endpoint can return.

Under the hood, Responses is a Some Response. This allows for the possibility that an endpoint might return one of several responses, via 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 UVerbs with more than one type.

data Response Source #

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.

responses :: Traversal' Responses Response Source #

Convenience optic to traverse over all the Responses within a Responses.

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.

Similar to Typeable, but also get the response Headers.

Instances

Instances details
Typeable a => HasResponse a Source # 
Instance details

Defined in Servant.API.Routes.Internal.Response

(HasResponse a, GetHeaderReps hs) => HasResponse (Headers hs a) Source # 
Instance details

Defined in Servant.API.Routes.Internal.Response

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 have HasResponse instances.
  • More impressively, its instances enforce that getResponses will only type-check for type-level lists of length 2 or more. This is because AllHasResponse will only ever be used by oneOfResponses, which is the only way to construct a Many @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 of Responses using Responses.

Of course, someone might import this Internal module and define a HasResponse a => AllHasResponse '[a] instance. Don't do that.

Instances

Instances details
(HasResponse a, AllHasResponse (b ': (c ': as))) => AllHasResponse (a ': (b ': (c ': as))) Source # 
Instance details

Defined in Servant.API.Routes.Internal.Response

(HasResponse a, HasResponse b) => AllHasResponse '[a, b] Source # 
Instance details

Defined in Servant.API.Routes.Internal.Response