git.iko.soy/typeable/servant
on master help sign in
more haddocks
commit60c7addb5e01fd5c6a71d262e45e93817e2e8fe1 authorAlp Mestanogullari <alpmestan@gmail.com> dateSat 22 Nov 2014, 19:19 (12 years ago) parentf983734
14 files changed+61−31
src/Servant.hs+1−3 src/Servant/API.hs+3−1 src/Servant/API/Delete.hs−1 src/Servant/API/Get.hs−1 src/Servant/API/Post.hs−1 src/Servant/API/Put.hs−1 src/Servant/API/Raw.hs−1 src/Servant/Client.hs+23−1 src/Servant/Common/BaseUrl.hs+1−4 src/Servant/Common/Text.hs+13−3 src/Servant/Docs.hs+1−8 src/Servant/Server.hs+18−4 src/Servant/Utils/StaticFiles.hs+1−1 test/Servant/ClientSpec.hs−1
src/Servant.hs+1−3
@@ -7,10 +7,9 @@ module Servant (
77 module Servant.Server,
88 -- | For accessing servant APIs as API clients.
99 module Servant.Client,
10− module Servant.Common.BaseUrl,
1110 -- | For generating documentation for servant APIs.
1211 module Servant.Docs,
13− -- | Helper module
12+ -- | Using your types in request paths and query string parameters
1413 module Servant.Common.Text,
1514 -- | Utilities on top of the servant core
1615 module Servant.Utils.ApiQuasiQuoting,
@@ -23,7 +22,6 @@ module Servant (
2322import Data.Proxy
2423import Servant.API
2524import Servant.Client
26−import Servant.Common.BaseUrl
2725import Servant.Common.Text
2826import Servant.Docs
2927import Servant.Server
src/Servant/API.hs+3−1
@@ -25,8 +25,9 @@ module Servant.API (
2525 module Servant.API.Put,
2626
2727 -- * Untyped endpoints
28− -- | Plugging in a wai 'Network.Wai.Application'
28+ -- | Plugging in a wai 'Network.Wai.Application', serving directories
2929 module Servant.API.Raw,
30+ module Servant.Utils.StaticFiles,
3031
3132 -- * Utilities
3233 -- | QuasiQuotes for endpoints
@@ -47,3 +48,4 @@ import Servant.API.ReqBody
4748import Servant.API.Sub
4849import Servant.Utils.ApiQuasiQuoting (sitemap)
4950import Servant.Utils.Links (mkLink)
51+import Servant.Utils.StaticFiles
src/Servant/API/Delete.hs−1
@@ -11,7 +11,6 @@ import Data.Typeable
1111import Network.HTTP.Types
1212import Network.Wai
1313import Servant.Client
14−import Servant.Common.BaseUrl
1514import Servant.Common.Req
1615import Servant.Docs
1716import Servant.Server
src/Servant/API/Get.hs−1
@@ -12,7 +12,6 @@ import Data.Typeable
1212import Network.HTTP.Types
1313import Network.Wai
1414import Servant.Client
15−import Servant.Common.BaseUrl
1615import Servant.Common.Req
1716import Servant.Docs
1817import Servant.Server
src/Servant/API/Post.hs−1
@@ -12,7 +12,6 @@ import Data.Typeable
1212import Network.HTTP.Types
1313import Network.Wai
1414import Servant.Client
15−import Servant.Common.BaseUrl
1615import Servant.Common.Req
1716import Servant.Docs
1817import Servant.Server
src/Servant/API/Put.hs−1
@@ -12,7 +12,6 @@ import Data.Typeable
1212import Network.HTTP.Types
1313import Network.Wai
1414import Servant.Client
15−import Servant.Common.BaseUrl
1615import Servant.Common.Req
1716import Servant.Docs
1817import Servant.Server
src/Servant/API/Raw.hs−1
@@ -9,7 +9,6 @@ import Data.Proxy
99import Network.HTTP.Types
1010import Network.Wai
1111import Servant.Client
12−import Servant.Common.BaseUrl
1312import Servant.Common.Req
1413import Servant.Docs hiding (Method)
1514import Servant.Server
src/Servant/Client.hs+23−1
@@ -1,17 +1,39 @@
11{-# LANGUAGE TypeFamilies #-}
22{-# LANGUAGE OverloadedStrings #-}
3−module Servant.Client where
3+-- | This module provides 'client' which can automatically generate
4+-- querying functions for each endpoint just from the type representing your
5+-- API.
6+module Servant.Client
7+ ( client
8+ , HasClient(..)
9+ , module Servant.Common.BaseUrl
10+ ) where
411
512import Data.Proxy
613
14+import Servant.Common.BaseUrl
715import Servant.Common.Req
816
917-- * Accessing APIs as a Client
1018
1119-- | 'client' allows you to produce operations to query an API from a client.
20+--
21+-- > type MyApi = "books" :> Get [Book] -- GET /books
22+-- > :<|> "books" :> ReqBody Book :> Post Book -- POST /books
23+-- >
24+-- > myApi :: Proxy MyApi
25+-- > myApi = Proxy
26+-- >
27+-- > getAllBooks :: BaseUrl -> EitherT String IO [Book]
28+-- > postNewBook :: Book -> BaseUrl -> EitherT String IO Book
29+-- > (getAllBooks :<|> postNewBook) = client myApi
1230client :: HasClient layout => Proxy layout -> Client layout
1331client p = clientWithRoute p defReq
1432
33+-- | This class lets us define how each API combinator
34+-- influences the creation of an HTTP request. Use 'client'
35+-- directly, this class implements the client-side
36+-- behavior of each combinator but you don't have to worry about it.
1537class HasClient layout where
1638 type Client layout :: *
1739 clientWithRoute :: Proxy layout -> Req -> Client layout
src/Servant/Common/BaseUrl.hs+1−4
@@ -1,9 +1,6 @@
11{-# LANGUAGE DeriveGeneric #-}
22{-# LANGUAGE ViewPatterns #-}
3−module Servant.Common.BaseUrl
4− ( Scheme(..)
5− , BaseUrl (..)
6− ) where
3+module Servant.Common.BaseUrl where
74
85import Data.List
96import GHC.Generics
src/Servant/Common/Text.hs+13−3
@@ -1,7 +1,10 @@
11{-# LANGUAGE FlexibleInstances #-}
22{-# LANGUAGE OverloadedStrings #-}
33{-# LANGUAGE TypeSynonymInstances #-}
4−module Servant.Common.Text where
4+module Servant.Common.Text
5+ ( FromText(..)
6+ , ToText(..)
7+ ) where
58
69import Data.String.Conversions
710import Data.Int
@@ -9,11 +12,11 @@ import Data.Text
912import Data.Text.Read
1013import Data.Word
1114
12−-- | For getting values from url captures, get parameters
15+-- | For getting values from url captures and query string parameters
1316class FromText a where
1417 fromText :: Text -> Maybe a
1518
16−-- | For putting values in paths, get parameters
19+-- | For putting values in paths and query string parameters
1720class ToText a where
1821 toText :: a -> Text
1922
@@ -29,11 +32,18 @@ instance FromText String where
2932instance ToText String where
3033 toText = cs
3134
35+-- |
36+-- > fromText "true" = Just True
37+-- > fromText "false" = Just False
38+-- > fromText _ = Nothing
3239instance FromText Bool where
3340 fromText "true" = Just True
3441 fromText "false" = Just False
3542 fromText _ = Nothing
3643
44+-- |
45+-- > toText True = "true"
46+-- > toText False = "false"
3747instance ToText Bool where
3848 toText True = "true"
3949 toText False = "false"
src/Servant/Docs.hs+1−8
@@ -4,14 +4,7 @@
44{-# LANGUAGE TemplateHaskell #-}
55
66-------------------------------------------------------------------------------
7−-- |
8−-- Module : Servant.Docs
9−-- License : BSD-style
10−-- Maintainer : alpmestan@gmail.com
11−-- Stability : provisional
12−-- Portability : TH, TypeFamilies, DeriveGeneric
13−--
14−-- This module lets you get API docs for free. It lets generate
7+-- | This module lets you get API docs for free. It lets generate
158-- an 'API' from the type that represents your API using 'docs':
169--
1710-- @docs :: 'HasDocs' api => 'Proxy' api -> 'API'@
src/Servant/Server.hs+18−4
@@ -1,10 +1,8 @@
11{-# LANGUAGE TypeFamilies #-}
22{-# LANGUAGE OverloadedStrings #-}
33
4−-- | This module lets you implement 'Server's for defined APIs. You will
5−-- probably need 'serve' (and look at the 'HasServer' type family), but
6−-- 'toApplication' and 'route' are rather internals.
7−
4+-- | This module lets you implement 'Server's for defined APIs. You'll
5+-- most likely just need 'serve'.
86module Servant.Server where
97
108import Data.Monoid
@@ -15,6 +13,22 @@ import Network.Wai
1513-- * Implementing Servers
1614
1715-- | 'serve' allows you to implement an API and produce a wai 'Application'.
16+--
17+-- Example:
18+--
19+-- > type MyApi = "books" :> Get [Book] -- GET /books
20+-- > :<|> "books" :> ReqBody Book :> Post Book -- POST /books
21+-- >
22+-- > server :: Server MyApi
23+-- > server = listAllBooks :<|> postBook
24+-- > where listAllBooks = ...
25+-- > postBook book = ...
26+-- >
27+-- > app :: Application
28+-- > app = serve myApi server
29+-- >
30+-- > main :: IO ()
31+-- > main = Network.Wai.Handler.Warp.run 8080 app
1832serve :: HasServer layout => Proxy layout -> Server layout -> Application
1933serve p server = toApplication (route p server)
2034
src/Servant/Utils/StaticFiles.hs+1−1
@@ -10,7 +10,7 @@ import Network.HTTP.Types
1010import Network.Wai
1111import Network.Wai.Application.Static
1212
13−import Servant.API
13+import Servant.API.Raw
1414import Servant.Docs
1515import Servant.Server
1616
test/Servant/ClientSpec.hs−1
@@ -25,7 +25,6 @@ import Test.QuickCheck
2525import Servant.API
2626import Servant.Client
2727import Servant.Server
28−import Servant.Common.BaseUrl
2928
3029import Servant.ServerSpec
3130