git.iko.soy/typeable/servant
on master help sign in
polish up cabal file, add a README
commit55eb020d10e9134ea26bbf72c649d5079f7e7283 authorAlp Mestanogullari <alpmestan@gmail.com> dateMon 8 Dec 2014, 10:56 (12 years ago) parent9c343fa
3 files changed+114−4
README.md+25 servant.cabal+89−4 servant.png
README.mdnew file+25
@@ -0,0 +1,25 @@
1+# servant
2+
3+[![Build Status](https://secure.travis-ci.org/haskell-servant/servant.svg)](http://travis-ci.org/haskell-servant/servant)
4+
5+![servant](https://raw.githubusercontent.com/haskell-servant/servant/master/servant.png)
6+
7+These libraries provides a family of combinators to define webservices and automatically generate the documentation and client-side querying functions for each endpoint.
8+
9+In order to minimize the dependencies depending on your needs, we provide these features under different packages.
10+
11+- `servant`, which contains everything you need to *declare* a webservice and *implement* an HTTP server with handlers for each endpoint.
12+- `servant-client`, which lets you derive automatically Haskell functions that let you query each endpoint of a *servant* webservice.
13+- `servant-docs`, which lets you generate API docs for your webservice.
14+- `servant-jquery`, which lets you derive Javascript functions (based on jquery) to query your API's endpoints, in the same spirit as `servant-client`.
15+
16+## Getting started
17+
18+We've written a [Getting Started](http://haskell-servant.github.io/getting-started/) guide that introduces the core types and features of servant. After this article, you should be able to write your first servant webservices, learning the rest from the haddocks' examples.
19+
20+## Repositories and Haddocks
21+
22+- The core [servant](http://github.com/haskell-servant) package - [docs](http://haskell-servant.github.io/servant/)
23+- (Haskell) client-side function generation with [servant-client](http://github.com/haskell-servant/servant-client) - [docs](http://haskell-servant.github.io/servant-client/)
24+- (Javascript) client-side function generation with [servant-jquery](http://github.com/haskell-servant/servant-jquery) - [docs](http://haskell-servant.github.io/servant-jquery/)
25+- API docs generation with [servant-docs](http://github.com/haskell-servant/servant-docs) - [docs](http://haskell-servant.github.io/servant-docs/)
servant.cabal+89−4
@@ -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
servant.pngnew file

Binary file not shown.