git.iko.soy/typeable/servant
on master help sign in
More haddocks for :<|>
commit407349c24562bb28421566bebbcc3a0cfc24f113 authorAlp Mestanogullari <alpmestan@gmail.com> dateSat 22 Nov 2014, 15:08 (12 years ago) parentd461726
1 file changed+31
src/Servant/API/Alternative.hs+31
src/Servant/API/Alternative.hs+31
@@ -9,9 +9,25 @@ import Servant.Docs
99import Servant.Server
1010
1111-- | Union of two APIs, first takes precedence in case of overlap.
12+--
13+-- Example:
14+--
15+-- > type MyApi = "books" :> Get [Book] -- GET /books
16+-- > :<|> "books" :> ReqBody Book :> Post Book -- POST /books
1217data a :<|> b = a :<|> b
1318infixr 8 :<|>
1419
20+-- | A server for @a ':<|>' b@ first tries to match the request again the route
21+-- represented by @a@ and if it fails tries @b@. You must provide a request
22+-- handler for each route.
23+--
24+-- > type MyApi = "books" :> Get [Book] -- GET /books
25+-- > :<|> "books" :> ReqBody Book :> Post Book -- POST /books
26+-- >
27+-- > server :: Server MyApi
28+-- > server = listAllBooks :<|> postBook
29+-- > where listAllBooks = ...
30+-- > postBook book = ...
1531instance (HasServer a, HasServer b) => HasServer (a :<|> b) where
1632 type Server (a :<|> b) = Server a :<|> Server b
1733 route Proxy (a :<|> b) request respond =
@@ -23,12 +39,27 @@ instance (HasServer a, HasServer b) => HasServer (a :<|> b) where
2339 where pa = Proxy :: Proxy a
2440 pb = Proxy :: Proxy b
2541
42+-- | A client querying function for @a ':<|>' b@ will actually hand you
43+-- one function for querying @a@ and another one for querying @b@,
44+-- stitching them together with ':<|>', which really is just like a pair.
45+--
46+-- > type MyApi = "books" :> Get [Book] -- GET /books
47+-- > :<|> "books" :> ReqBody Book :> Post Book -- POST /books
48+-- >
49+-- > myApi :: Proxy MyApi
50+-- > myApi = Proxy
51+-- >
52+-- > getAllBooks :: BaseUrl -> EitherT String IO [Book]
53+-- > postNewBook :: Book -> BaseUrl -> EitherT String IO Book
54+-- > (getAllBooks :<|> postNewBook) = client myApi
2655instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
2756 type Client (a :<|> b) = Client a :<|> Client b
2857 clientWithRoute Proxy req =
2958 clientWithRoute (Proxy :: Proxy a) req :<|>
3059 clientWithRoute (Proxy :: Proxy b) req
3160
61+-- | The generated docs for @a ':<|>' b@ just append the docs
62+-- for @a@ with the docs for @b@.
3263instance (HasDocs layout1, HasDocs layout2)
3364 => HasDocs (layout1 :<|> layout2) where
3465