@@ -1,7 +1,89 @@
1name: servant
1name: servant
2version: 0.2
2version: 0.2
3−-- synopsis:
3+synopsis: A family of combinators for defining webservices APIs and serving them
4−-- description:
4+description:
5+ A family of combinators for defining webservices APIs and serving them
7+ You can learn about the basic in <http://haskell-servant.github.io/getting-started/ the getting started> guide.
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.
12+ > {-# LANGUAGE DataKinds #-}
13+ > {-# LANGUAGE PolyKinds #-}
14+ > {-# LANGUAGE TypeFamilies #-}
15+ > {-# LANGUAGE DeriveGeneric #-}
16+ > {-# LANGUAGE TypeOperators #-}
17+ > {-# LANGUAGE OverloadedStrings #-}
23+ > import GHC.Generics
25+ > import Network.Wai.Handler.Warp
31+ > -- | A greet message data type
32+ > newtype Greet = Greet { msg :: Text }
33+ > deriving (Generic, Show)
35+ > instance FromJSON Greet
36+ > instance ToJSON Greet
38+ > -- API specification
40+ > -- GET /hello/:name?capital={true, false}
41+ -- returns a Greet as JSON
42+ > "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get Greet
44+ > -- POST /greet with a Greet as JSON in the request body,
45+ > -- returns a Greet as JSON
46+ > :<|> "greet" :> ReqBody Greet :> Post Greet
48+ > -- DELETE /greet/:greetid
49+ > :<|> "greet" :> Capture "greetid" Text :> Delete
51+ > testApi :: Proxy TestApi
54+ > -- Server-side handlers.
56+ > -- There's one handler per endpoint, which, just like in the type
57+ > -- that represents the API, are glued together using :<|>.
59+ > -- Each handler runs in the 'EitherT (Int, String) IO' monad.
60+ > server :: Server TestApi
61+ > server = helloH :<|> postGreetH :<|> deleteGreetH
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
67+ > postGreetH greet = return greet
69+ > deleteGreetH _ = return ()
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
78+ > -- 'run' comes from Network.Wai.Handler.Warp
79+ > runTestServer :: Port -> IO ()
80+ > runTestServer port = run port test
82+ > -- Put this all to work!
84+ > main = runTestServer 8001
85+homepage: http://haskell-servant.github.io/
86+Bug-reports: http://github.com/haskell-servant/servant/issues
5license: BSD3
87license: BSD3
6license-file: LICENSE
88license-file: LICENSE
7author: Alp Mestanogullari, Sönke Hahn, Julian K. Arni
89author: Alp Mestanogullari, Sönke Hahn, Julian K. Arni
@@ -11,6 +93,9 @@ category: Web
11build-type: Simple
93build-type: Simple
12cabal-version: >=1.10
94cabal-version: >=1.10
13tested-with: GHC >= 7.8
95tested-with: GHC >= 7.8
96+source-repository head
98+ location: http://github.com/haskell-servant/servant.git
16 exposed-modules:
101 exposed-modules:
@@ -52,12 +137,12 @@ library
53 hs-source-dirs: src
138 hs-source-dirs: src
54 default-language: Haskell2010
139 default-language: Haskell2010
55− ghc-options: -O0 -Wall
140+ ghc-options: -Wall
57executable greet
142executable greet
58 main-is: greet.hs
143 main-is: greet.hs
59 hs-source-dirs: example
144 hs-source-dirs: example
60− ghc-options: -O0 -Wall
145+ ghc-options: -Wall
61 default-language: Haskell2010
146 default-language: Haskell2010
62 build-depends:
147 build-depends: