Safe Haskell | None |
---|---|
Language | Haskell2010 |
Types, but really kinds, which represent the structure of an API.
- data Api star
- data Path star
- = Const Symbol
- | HeaderAs HeaderName Symbol
- | Seg Symbol star
- | Header HeaderName star
- | Wildcard
- data Handler star
- = Method Verb [(Status, Output star)]
- | CaptureBody [star] star (Handler star)
- | CaptureHeaders [(HeaderName, star)] (Handler star)
- | CaptureQuery [(Symbol, star)] (Handler star)
- data Output star = Respond [(HeaderName, star)] (Body star)
- data Body star
- type (:::) a b = `(a, b)`
- data family Sing a
- type Endpoint ann ms = Endpoint ann ms
- type OneOf apis = OneOf apis
- type Abstract = Abstract
- type (:>) a b = a :> b
- type Const sym = Const sym
- type HeaderAs ty sym = HeaderAs ty sym
- type Seg sym ty = Seg sym ty
- type Header name ty = Header name ty
- type Wildcard = Wildcard
- type Method verb responses = Method verb responses
- type CaptureBody cTypes ty method = CaptureBody cTypes ty method
- type CaptureHeaders hdrs method = CaptureHeaders hdrs method
- type CaptureQuery query method = CaptureQuery query method
- type Respond hdrs body = Respond hdrs body
- type HasBody ctypes ty = HasBody ctypes ty
- type Empty = Empty
API types/kinds
Endpoint star [Handler star] | An
|
OneOf [Api star] |
|
Abstract |
|
(Path star) :> (Api star) infixr 5 | Qualify an API using a series of |
SingI (Api *) (Abstract *) Source | |
SingI [Api *] ts => SingI (Api *) (OneOf * ts) Source | |
(SingI (Path *) p, SingI (Api *) k) => SingI (Api *) ((:>) * p k) Source | |
(SingI * t, SingI [Handler *] ts) => SingI (Api *) (Endpoint * t ts) Source | |
data Sing (Api *) where
|
Generalized path segments match against data in the request.
Const Symbol | Matches if the request has a non-empty remaining path and the next segment matches exactly |
HeaderAs HeaderName Symbol | Matches if the request has a given header and its value matches exactly (!) |
Seg Symbol star | Matches if the request has a non-empty remaining path. The next segment is "captured", provided to the server implementation. |
Header HeaderName star | Always matches, "capturing" the value of a header, or |
Wildcard | Always matches, "captures" the remaining path segments as a list of text values. May just capture the empty list. |
SingI (Path *) (Wildcard *) Source | |
SingI Symbol s => SingI (Path *) (Const * s) Source | |
(SingI HeaderName n, SingI * t) => SingI (Path *) (Header * n t) Source | |
(SingI Symbol n, SingI * t) => SingI (Path *) (Seg * n t) Source | |
(SingI HeaderName n, SingI Symbol v) => SingI (Path *) (HeaderAs * n v) Source | |
data Sing (Path *) where
|
A Handler
is a single HTTP verb response handled at a given Endpoint
.
In order to complete a Handler'
s operation it may demand data from the
request such as headers or the request body.
Method Verb [(Status, Output star)] | A "core" |
CaptureBody [star] star (Handler star) | Augment a |
CaptureHeaders [(HeaderName, star)] (Handler star) | Augment a |
CaptureQuery [(Symbol, star)] (Handler star) | Augment a |
(SingI Verb v, SingI [(,) Status (Output *)] ts) => SingI (Handler *) (Method * v ts) Source | |
(SingI [(,) HeaderName *] ts, SingI (Handler *) k) => SingI (Handler *) (CaptureHeaders * ts k) Source | |
(SingI [(,) Symbol *] ts, SingI (Handler *) k) => SingI (Handler *) (CaptureQuery * ts k) Source | |
(SingI [*] ts, SingI * a, SingI (Handler *) k) => SingI (Handler *) (CaptureBody * ts a k) Source | |
data Sing (Handler *) where
|
Describes an output from an API under a given status.
Respond [(HeaderName, star)] (Body star) |
Handler
responses may opt to include a response body or not.
Syntax sugar
Singletons
data family Sing a
The singleton kind-indexed data family.
Type aliases
Eliminates need for single-quoting the DataKind
-lifted types.
Api
Path
Handler
type CaptureBody cTypes ty method = CaptureBody cTypes ty method Source
type CaptureHeaders hdrs method = CaptureHeaders hdrs method Source
type CaptureQuery query method = CaptureQuery query method Source