on master help sign in
more haddocks
60c7addAlp Mestanogullari
src/Servant.hs+1−3
@@ -7,10 +7,9 @@ module Servant (
7 module Servant.Server,
7 module Servant.Server,
8 -- | For accessing servant APIs as API clients.
8 -- | For accessing servant APIs as API clients.
9 module Servant.Client,
9 module Servant.Client,
10− module Servant.Common.BaseUrl,
11 -- | For generating documentation for servant APIs.
10 -- | For generating documentation for servant APIs.
12 module Servant.Docs,
11 module Servant.Docs,
13− -- | Helper module
12+ -- | Using your types in request paths and query string parameters
14 module Servant.Common.Text,
13 module Servant.Common.Text,
15 -- | Utilities on top of the servant core
14 -- | Utilities on top of the servant core
16 module Servant.Utils.ApiQuasiQuoting,
15 module Servant.Utils.ApiQuasiQuoting,
@@ -23,7 +22,6 @@ module Servant (
23import Data.Proxy
22import Data.Proxy
24import Servant.API
23import Servant.API
25import Servant.Client
24import Servant.Client
26−import Servant.Common.BaseUrl
27import Servant.Common.Text
25import Servant.Common.Text
28import Servant.Docs
26import Servant.Docs
29import Servant.Server
27import Servant.Server
src/Servant/API.hs+3−1
@@ -25,8 +25,9 @@ module Servant.API (
25 module Servant.API.Put,
25 module Servant.API.Put,
26
26
27 -- * Untyped endpoints
27 -- * Untyped endpoints
28− -- | Plugging in a wai 'Network.Wai.Application'
28+ -- | Plugging in a wai 'Network.Wai.Application', serving directories
29 module Servant.API.Raw,
29 module Servant.API.Raw,
30+ module Servant.Utils.StaticFiles,
30
31
31 -- * Utilities
32 -- * Utilities
32 -- | QuasiQuotes for endpoints
33 -- | QuasiQuotes for endpoints
@@ -47,3 +48,4 @@ import Servant.API.ReqBody
47import Servant.API.Sub
48import Servant.API.Sub
48import Servant.Utils.ApiQuasiQuoting (sitemap)
49import Servant.Utils.ApiQuasiQuoting (sitemap)
49import Servant.Utils.Links (mkLink)
50import Servant.Utils.Links (mkLink)
51+import Servant.Utils.StaticFiles
src/Servant/API/Delete.hs−1
@@ -11,7 +11,6 @@ import Data.Typeable
11import Network.HTTP.Types
11import Network.HTTP.Types
12import Network.Wai
12import Network.Wai
13import Servant.Client
13import Servant.Client
14−import Servant.Common.BaseUrl
15import Servant.Common.Req
14import Servant.Common.Req
16import Servant.Docs
15import Servant.Docs
17import Servant.Server
16import Servant.Server
src/Servant/API/Get.hs−1
@@ -12,7 +12,6 @@ import Data.Typeable
12import Network.HTTP.Types
12import Network.HTTP.Types
13import Network.Wai
13import Network.Wai
14import Servant.Client
14import Servant.Client
15−import Servant.Common.BaseUrl
16import Servant.Common.Req
15import Servant.Common.Req
17import Servant.Docs
16import Servant.Docs
18import Servant.Server
17import Servant.Server
src/Servant/API/Post.hs−1
@@ -12,7 +12,6 @@ import Data.Typeable
12import Network.HTTP.Types
12import Network.HTTP.Types
13import Network.Wai
13import Network.Wai
14import Servant.Client
14import Servant.Client
15−import Servant.Common.BaseUrl
16import Servant.Common.Req
15import Servant.Common.Req
17import Servant.Docs
16import Servant.Docs
18import Servant.Server
17import Servant.Server
src/Servant/API/Put.hs−1
@@ -12,7 +12,6 @@ import Data.Typeable
12import Network.HTTP.Types
12import Network.HTTP.Types
13import Network.Wai
13import Network.Wai
14import Servant.Client
14import Servant.Client
15−import Servant.Common.BaseUrl
16import Servant.Common.Req
15import Servant.Common.Req
17import Servant.Docs
16import Servant.Docs
18import Servant.Server
17import Servant.Server
src/Servant/API/Raw.hs−1
@@ -9,7 +9,6 @@ import Data.Proxy
9import Network.HTTP.Types
9import Network.HTTP.Types
10import Network.Wai
10import Network.Wai
11import Servant.Client
11import Servant.Client
12−import Servant.Common.BaseUrl
13import Servant.Common.Req
12import Servant.Common.Req
14import Servant.Docs hiding (Method)
13import Servant.Docs hiding (Method)
15import Servant.Server
14import Servant.Server
src/Servant/Client.hs+23−1
@@ -1,17 +1,39 @@
1{-# LANGUAGE TypeFamilies #-}
1{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3+-- | This module provides 'client' which can automatically generate
4+-- querying functions for each endpoint just from the type representing your
5+-- API.
3−module Servant.Client where
6+module Servant.Client
7+ ( client
8+ , HasClient(..)
9+ , module Servant.Common.BaseUrl
10+ ) where
4
11
5import Data.Proxy
12import Data.Proxy
6
13
14+import Servant.Common.BaseUrl
7import Servant.Common.Req
15import Servant.Common.Req
8
16
9-- * Accessing APIs as a Client
17-- * Accessing APIs as a Client
10
18
11-- | 'client' allows you to produce operations to query an API from a client.
19-- | '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
12client :: HasClient layout => Proxy layout -> Client layout
30client :: HasClient layout => Proxy layout -> Client layout
13client p = clientWithRoute p defReq
31client p = clientWithRoute p defReq
14
32
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.
15class HasClient layout where
37class HasClient layout where
16 type Client layout :: *
38 type Client layout :: *
17 clientWithRoute :: Proxy layout -> Req -> Client layout
39 clientWithRoute :: Proxy layout -> Req -> Client layout
src/Servant/Common/BaseUrl.hs+1−4
@@ -1,9 +1,6 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE ViewPatterns #-}
2{-# LANGUAGE ViewPatterns #-}
3−module Servant.Common.BaseUrl
3+module Servant.Common.BaseUrl where
4− ( Scheme(..)
5− , BaseUrl (..)
6− ) where
7
4
8import Data.List
5import Data.List
9import GHC.Generics
6import GHC.Generics
src/Servant/Common/Text.hs+13−3
@@ -1,7 +1,10 @@
1{-# LANGUAGE FlexibleInstances #-}
1{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE TypeSynonymInstances #-}
3{-# LANGUAGE TypeSynonymInstances #-}
4−module Servant.Common.Text where
4+module Servant.Common.Text
5+ ( FromText(..)
6+ , ToText(..)
7+ ) where
5
8
6import Data.String.Conversions
9import Data.String.Conversions
7import Data.Int
10import Data.Int
@@ -9,11 +12,11 @@ import Data.Text
9import Data.Text.Read
12import Data.Text.Read
10import Data.Word
13import Data.Word
11
14
12−-- | For getting values from url captures, get parameters
15+-- | For getting values from url captures and query string parameters
13class FromText a where
16class FromText a where
14 fromText :: Text -> Maybe a
17 fromText :: Text -> Maybe a
15
18
16−-- | For putting values in paths, get parameters
19+-- | For putting values in paths and query string parameters
17class ToText a where
20class ToText a where
18 toText :: a -> Text
21 toText :: a -> Text
19
22
@@ -29,11 +32,18 @@ instance FromText String where
29instance ToText String where
32instance ToText String where
30 toText = cs
33 toText = cs
31
34
35+-- |
36+-- > fromText "true" = Just True
37+-- > fromText "false" = Just False
38+-- > fromText _ = Nothing
32instance FromText Bool where
39instance FromText Bool where
33 fromText "true" = Just True
40 fromText "true" = Just True
34 fromText "false" = Just False
41 fromText "false" = Just False
35 fromText _ = Nothing
42 fromText _ = Nothing
36
43
44+-- |
45+-- > toText True = "true"
46+-- > toText False = "false"
37instance ToText Bool where
47instance ToText Bool where
38 toText True = "true"
48 toText True = "true"
39 toText False = "false"
49 toText False = "false"
src/Servant/Docs.hs+1−8
@@ -4,14 +4,7 @@
4{-# LANGUAGE TemplateHaskell #-}
4{-# LANGUAGE TemplateHaskell #-}
5
5
6-------------------------------------------------------------------------------
6-------------------------------------------------------------------------------
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
15-- an 'API' from the type that represents your API using 'docs':
8-- an 'API' from the type that represents your API using 'docs':
16--
9--
17-- @docs :: 'HasDocs' api => 'Proxy' api -> 'API'@
10-- @docs :: 'HasDocs' api => 'Proxy' api -> 'API'@
src/Servant/Server.hs+18−4
@@ -1,10 +1,8 @@
1{-# LANGUAGE TypeFamilies #-}
1{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3
3
4−-- | This module lets you implement 'Server's for defined APIs. You will
4+-- | This module lets you implement 'Server's for defined APIs. You'll
5−-- probably need 'serve' (and look at the 'HasServer' type family), but
5+-- most likely just need 'serve'.
6−-- 'toApplication' and 'route' are rather internals.
7−
8module Servant.Server where
6module Servant.Server where
9
7
10import Data.Monoid
8import Data.Monoid
@@ -15,6 +13,22 @@ import Network.Wai
15-- * Implementing Servers
13-- * Implementing Servers
16
14
17-- | 'serve' allows you to implement an API and produce a wai 'Application'.
15-- | '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
18serve :: HasServer layout => Proxy layout -> Server layout -> Application
32serve :: HasServer layout => Proxy layout -> Server layout -> Application
19serve p server = toApplication (route p server)
33serve p server = toApplication (route p server)
20
34
src/Servant/Utils/StaticFiles.hs+1−1
@@ -10,7 +10,7 @@ import Network.HTTP.Types
10import Network.Wai
10import Network.Wai
11import Network.Wai.Application.Static
11import Network.Wai.Application.Static
12
12
13−import Servant.API
13+import Servant.API.Raw
14import Servant.Docs
14import Servant.Docs
15import Servant.Server
15import Servant.Server
16
16
test/Servant/ClientSpec.hs−1
@@ -25,7 +25,6 @@ import Test.QuickCheck
25import Servant.API
25import Servant.API
26import Servant.Client
26import Servant.Client
27import Servant.Server
27import Servant.Server
28−import Servant.Common.BaseUrl
29
28
30import Servant.ServerSpec
29import Servant.ServerSpec
31
30