Copyright | Dennis Gosnell 2017 |
---|---|
License | BSD3 |
Maintainer | Dennis Gosnell (cdep.illabout@gmail.com) |
Stability | experimental |
Portability | unknown |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Throws (e :: *)
- data NoThrow
- data Throwing (e :: [*])
- type family ThrowingNonterminal api where ...
- class ErrStatus e where
- toErrStatus :: e -> Status
- type family AllErrStatus (es :: [k]) :: Constraint where ...
Documentation
Throws
is used in Servant API definitions and signifies that an API will
throw the given error.
Here is an example of how to create an API that potentially returns a
String
as an error, or an Int
on success:
>>>
import Servant.API (Get, JSON, (:>))
>>>
type API = Throws String :> Get '[JSON] Int
NoThrow
is used to indicate that an API will not throw an error, but
that it will still return a response wrapped in a
Envelope
.
Examples
Create an API using NoThrow
:
>>>
import Servant.API (Get, JSON, (:>))
>>>
type API = NoThrow :> Get '[JSON] Int
A servant-server handler for this type would look like the following:
apiHandler ::Handler
(Envelope
'[] Int) apiHandler =pureSuccEnvelope
3
data Throwing (e :: [*]) Source #
This is used internally and should not be used by end-users.
Instances
HasDocs (Throwing (Snoc es e) :> api) => HasDocs (Throwing es :> (Throws e :> api) :: Type) Source # | When a |
(CreateRespBodiesFor es ctypes, HasDocs (Verb method status ctypes (Envelope es a))) => HasDocs (Throwing es :> Verb method status ctypes a :: Type) Source # | When |
type family ThrowingNonterminal api where ... Source #
class ErrStatus e where Source #
Note that clients generated by servant-client
currently don't handle
status codes outside the 2XX
range correctly.
Take a look at the README for more details.
toErrStatus :: e -> Status Source #
type family AllErrStatus (es :: [k]) :: Constraint where ... Source #
AllErrStatus '[] = () | |
AllErrStatus (a ': as) = (ErrStatus a, AllErrStatus as) |
>>>
:set -XDataKinds
>>>
:set -XTypeOperators