@@ -1,7 +1,89 @@
11name: servant
22version: 0.2
3−-- synopsis:
4−-- description:
3+synopsis: A family of combinators for defining webservices APIs and serving them
4+description:
5+ A family of combinators for defining webservices APIs and serving them
6+ .
7+ You can learn about the basic in <http://haskell-servant.github.io/getting-started/ the getting started> guide.
8+ .
9+ Here's a runnable example, with comments that defines a dummy API and
10+ implements a webserver that serves this API. You can find it <https://github.com/haskell-servant/servant/blob/master/example/greet.hs here> too.
11+ .
12+ > {-# LANGUAGE DataKinds #-}
13+ > {-# LANGUAGE PolyKinds #-}
14+ > {-# LANGUAGE TypeFamilies #-}
15+ > {-# LANGUAGE DeriveGeneric #-}
16+ > {-# LANGUAGE TypeOperators #-}
17+ > {-# LANGUAGE OverloadedStrings #-}
18+ >
19+ > import Data.Aeson
20+ > import Data.Monoid
21+ > import Data.Proxy
22+ > import Data.Text
23+ > import GHC.Generics
24+ > import Network.Wai
25+ > import Network.Wai.Handler.Warp
26+ >
27+ > import Servant
28+ >
29+ > -- * Example
30+ >
31+ > -- | A greet message data type
32+ > newtype Greet = Greet { msg :: Text }
33+ > deriving (Generic, Show)
34+ >
35+ > instance FromJSON Greet
36+ > instance ToJSON Greet
37+ >
38+ > -- API specification
39+ > type TestApi =
40+ > -- GET /hello/:name?capital={true, false}
41+ -- returns a Greet as JSON
42+ > "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get Greet
43+ >
44+ > -- POST /greet with a Greet as JSON in the request body,
45+ > -- returns a Greet as JSON
46+ > :<|> "greet" :> ReqBody Greet :> Post Greet
47+ >
48+ > -- DELETE /greet/:greetid
49+ > :<|> "greet" :> Capture "greetid" Text :> Delete
50+ >
51+ > testApi :: Proxy TestApi
52+ > testApi = Proxy
53+ >
54+ > -- Server-side handlers.
55+ > --
56+ > -- There's one handler per endpoint, which, just like in the type
57+ > -- that represents the API, are glued together using :<|>.
58+ > --
59+ > -- Each handler runs in the 'EitherT (Int, String) IO' monad.
60+ > server :: Server TestApi
61+ > server = helloH :<|> postGreetH :<|> deleteGreetH
62+ >
63+ > where helloH name Nothing = helloH name (Just False)
64+ > helloH name (Just False) = return . Greet $ "Hello, " <> name
65+ > helloH name (Just True) = return . Greet . toUpper $ "Hello, " <> name
66+ >
67+ > postGreetH greet = return greet
68+ >
69+ > deleteGreetH _ = return ()
70+ >
71+ > -- Turn the server into a WAI app. 'serve' is provided by servant,
72+ > -- more precisely by the Servant.Server module.
73+ > test :: Application
74+ > test = serve testApi server
75+ >
76+ > -- Run the server.
77+ > --
78+ > -- 'run' comes from Network.Wai.Handler.Warp
79+ > runTestServer :: Port -> IO ()
80+ > runTestServer port = run port test
81+ >
82+ > -- Put this all to work!
83+ > main :: IO ()
84+ > main = runTestServer 8001
85+homepage: http://haskell-servant.github.io/
86+Bug-reports: http://github.com/haskell-servant/servant/issues
587license: BSD3
688license-file: LICENSE
789author: Alp Mestanogullari, Sönke Hahn, Julian K. Arni
@@ -11,6 +93,9 @@ category: Web
1193build-type: Simple
1294cabal-version: >=1.10
1395tested-with: GHC >= 7.8
96+source-repository head
97+ type: git
98+ location: http://github.com/haskell-servant/servant.git
1499
15100library
16101 exposed-modules:
@@ -52,12 +137,12 @@ library
52137 , warp
53138 hs-source-dirs: src
54139 default-language: Haskell2010
55− ghc-options: -O0 -Wall
140+ ghc-options: -Wall
56141
57142executable greet
58143 main-is: greet.hs
59144 hs-source-dirs: example
60− ghc-options: -O0 -Wall
145+ ghc-options: -Wall
61146 default-language: Haskell2010
62147 build-depends:
63148 base