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 #-}
15import Network.HTTP.Client (newManager, defaultManagerSettings)
22type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
23 :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book -- POST /books
28-- 'client' allows you to produce operations to query an API from a client.
29postNewBook :: Book -> ClientM Book
30getAllBooks :: ClientM [Book]
31(getAllBooks :<|> postNewBook) = client myApi
36 manager' <- newManager defaultManagerSettings
37 res <- runClientM getAllBooks (mkClientEnv manager' (BaseUrl Http "localhost" 8081 ""))
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