Updated docs

This commit is contained in:
Catherine Galkina 2019-09-08 13:32:25 +03:00 committed by Oleg Grenrus
parent dcf307d67a
commit 8550926d90
2 changed files with 16 additions and 17 deletions

View File

@ -177,13 +177,12 @@ type UserAPI5 = "user" :> Capture "userid" Integer :> Get '[JSON] User
-- except that we explicitly say that "userid" -- except that we explicitly say that "userid"
-- must be an integer -- must be an integer
:<|> "user" :> Capture "userid" Integer :> DeleteNoContent '[JSON] NoContent :<|> "user" :> Capture "userid" Integer :> DeleteNoContent
-- equivalent to 'DELETE /user/:userid' -- equivalent to 'DELETE /user/:userid'
``` ```
In the second case, `DeleteNoContent` specifies a 204 response code, In the second case, `DeleteNoContent` specifies a 204 response code
`JSON` specifies the content types on which the handler will match, and that the response will always be empty.
and `NoContent` says that the response will always be empty.
### `QueryParam`, `QueryParams`, `QueryFlag` ### `QueryParam`, `QueryParams`, `QueryFlag`

View File

@ -830,7 +830,7 @@ type UserAPI3 = -- view the user with given userid, in JSON
Capture "userid" Int :> Get '[JSON] User Capture "userid" Int :> Get '[JSON] User
:<|> -- delete the user with given userid. empty response :<|> -- delete the user with given userid. empty response
Capture "userid" Int :> DeleteNoContent '[JSON] NoContent Capture "userid" Int :> DeleteNoContent
``` ```
We can instead factor out the `userid`: We can instead factor out the `userid`:
@ -838,7 +838,7 @@ We can instead factor out the `userid`:
``` haskell ``` haskell
type UserAPI4 = Capture "userid" Int :> type UserAPI4 = Capture "userid" Int :>
( Get '[JSON] User ( Get '[JSON] User
:<|> DeleteNoContent '[JSON] NoContent :<|> DeleteNoContent
) )
``` ```
@ -896,13 +896,13 @@ type API1 = "users" :>
-- we factor out the Request Body -- we factor out the Request Body
type API2 = ReqBody '[JSON] User :> type API2 = ReqBody '[JSON] User :>
( Get '[JSON] User -- just display the same user back, don't register it ( Get '[JSON] User -- just display the same user back, don't register it
:<|> PostNoContent '[JSON] NoContent -- register the user. empty response :<|> PostNoContent -- register the user. empty response
) )
-- we factor out a Header -- we factor out a Header
type API3 = Header "Authorization" Token :> type API3 = Header "Authorization" Token :>
( Get '[JSON] SecretData -- get some secret data, if authorized ( Get '[JSON] SecretData -- get some secret data, if authorized
:<|> ReqBody '[JSON] SecretData :> PostNoContent '[JSON] NoContent -- add some secret data, if authorized :<|> ReqBody '[JSON] SecretData :> PostNoContent -- add some secret data, if authorized
) )
newtype Token = Token ByteString newtype Token = Token ByteString
@ -915,11 +915,11 @@ API type only at the end.
``` haskell ``` haskell
type UsersAPI = type UsersAPI =
Get '[JSON] [User] -- list users Get '[JSON] [User] -- list users
:<|> ReqBody '[JSON] User :> PostNoContent '[JSON] NoContent -- add a user :<|> ReqBody '[JSON] User :> PostNoContent -- add a user
:<|> Capture "userid" Int :> :<|> Capture "userid" Int :>
( Get '[JSON] User -- view a user ( Get '[JSON] User -- view a user
:<|> ReqBody '[JSON] User :> PutNoContent '[JSON] NoContent -- update a user :<|> ReqBody '[JSON] User :> PutNoContent -- update a user
:<|> DeleteNoContent '[JSON] NoContent -- delete a user :<|> DeleteNoContent -- delete a user
) )
usersServer :: Server UsersAPI usersServer :: Server UsersAPI
@ -948,11 +948,11 @@ usersServer = getUsers :<|> newUser :<|> userOperations
``` haskell ``` haskell
type ProductsAPI = type ProductsAPI =
Get '[JSON] [Product] -- list products Get '[JSON] [Product] -- list products
:<|> ReqBody '[JSON] Product :> PostNoContent '[JSON] NoContent -- add a product :<|> ReqBody '[JSON] Product :> PostNoContent -- add a product
:<|> Capture "productid" Int :> :<|> Capture "productid" Int :>
( Get '[JSON] Product -- view a product ( Get '[JSON] Product -- view a product
:<|> ReqBody '[JSON] Product :> PutNoContent '[JSON] NoContent -- update a product :<|> ReqBody '[JSON] Product :> PutNoContent -- update a product
:<|> DeleteNoContent '[JSON] NoContent -- delete a product :<|> DeleteNoContent -- delete a product
) )
data Product = Product { productId :: Int } data Product = Product { productId :: Int }
@ -996,11 +996,11 @@ abstract that away:
-- indexed by values of type 'i' -- indexed by values of type 'i'
type APIFor a i = type APIFor a i =
Get '[JSON] [a] -- list 'a's Get '[JSON] [a] -- list 'a's
:<|> ReqBody '[JSON] a :> PostNoContent '[JSON] NoContent -- add an 'a' :<|> ReqBody '[JSON] a :> PostNoContent -- add an 'a'
:<|> Capture "id" i :> :<|> Capture "id" i :>
( Get '[JSON] a -- view an 'a' given its "identifier" of type 'i' ( Get '[JSON] a -- view an 'a' given its "identifier" of type 'i'
:<|> ReqBody '[JSON] a :> PutNoContent '[JSON] NoContent -- update an 'a' :<|> ReqBody '[JSON] a :> PutNoContent -- update an 'a'
:<|> DeleteNoContent '[JSON] NoContent -- delete an 'a' :<|> DeleteNoContent -- delete an 'a'
) )
-- Build the appropriate 'Server' -- Build the appropriate 'Server'