3
5This library lets you automatically derive Haskell functions that let you query each endpoint of a *servant* webservice.
10{-# LANGUAGE DataKinds #-}
11{-# LANGUAGE TypeOperators #-}
16import Servant.HttpStreams
21type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
22 :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book -- POST /books
27-- 'client' allows you to produce operations to query an API from a client.
28postNewBook :: Book -> ClientM Book
29getAllBooks :: ClientM [Book]
30(getAllBooks :<|> postNewBook) = client myApi
32-- the IOException happens already in withClientEnvIO
35 let burl = BaseUrl Http "localhost" 8081 ""
36 withClientEnvIO burl $ \env -> do
37 res <- runClientM getAllBooks env
39 Left err -> putStrLn $ "Error: " ++ show err
40 Right books -> print books
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list