Rewrite the part on verbs.
This commit is contained in:
parent
7ae6ac6809
commit
0a2235261c
1 changed files with 21 additions and 10 deletions
|
@ -88,19 +88,30 @@ type UserAPI3 = "users" :> "list-all" :> "now" :> Get '[JSON] [User]
|
||||||
### `Delete`, `Get`, `Patch`, `Post` and `Put`
|
### `Delete`, `Get`, `Patch`, `Post` and `Put`
|
||||||
|
|
||||||
|
|
||||||
These 5 combinators are very similar except that they each describe a
|
The `Get` combinator is defined in terms of the more general `Verb`:
|
||||||
different HTTP method. This is how they're declared
|
|
||||||
|
|
||||||
``` haskell ignore
|
``` haskell ignore
|
||||||
data Delete (contentTypes :: [*]) a
|
data Verb method (statusCode :: Nat) (contentType :: [*]) a
|
||||||
data Get (contentTypes :: [*]) a
|
type Get = Verb 'GET 200
|
||||||
data Patch (contentTypes :: [*]) a
|
|
||||||
data Post (contentTypes :: [*]) a
|
|
||||||
data Put (contentTypes :: [*]) a
|
|
||||||
```
|
```
|
||||||
|
|
||||||
An endpoint ends with one of the 5 combinators above (unless you write your
|
There are other predefined type synonyms for other common HTTP methods,
|
||||||
own). Examples:
|
such as e.g.:
|
||||||
|
``` haskell ignore
|
||||||
|
data Delete = Verb 'DELETE 200
|
||||||
|
data Patch = Verb 'PATCH 200
|
||||||
|
data Post = Verb 'POST 200
|
||||||
|
data Put = Verb 'PUT 200
|
||||||
|
```
|
||||||
|
|
||||||
|
There are also variants that do not return a 200 status code, such
|
||||||
|
as for example:
|
||||||
|
``` haskell ignore
|
||||||
|
type PostCreated = Verb 'POST 201
|
||||||
|
type PostAccepted = Verb 'POST 202
|
||||||
|
```
|
||||||
|
|
||||||
|
An endpoint always ends with a variant of the `Verb` combinator
|
||||||
|
(unless you write your own combinators). Examples:
|
||||||
|
|
||||||
``` haskell
|
``` haskell
|
||||||
type UserAPI4 = "users" :> Get '[JSON] [User]
|
type UserAPI4 = "users" :> Get '[JSON] [User]
|
||||||
|
|
Loading…
Reference in a new issue