2014-10-21 15:25:34 +02:00
|
|
|
name: servant
|
|
|
|
version: 0.2
|
2014-12-08 10:56:02 +01:00
|
|
|
synopsis: A family of combinators for defining webservices APIs and serving them
|
|
|
|
description:
|
|
|
|
A family of combinators for defining webservices APIs and serving them
|
|
|
|
.
|
|
|
|
You can learn about the basic in <http://haskell-servant.github.io/getting-started/ the getting started> guide.
|
|
|
|
.
|
|
|
|
Here's a runnable example, with comments that defines a dummy API and
|
|
|
|
implements a webserver that serves this API. You can find it <https://github.com/haskell-servant/servant/blob/master/example/greet.hs here> too.
|
|
|
|
.
|
|
|
|
> {-# LANGUAGE DataKinds #-}
|
|
|
|
> {-# LANGUAGE PolyKinds #-}
|
|
|
|
> {-# LANGUAGE TypeFamilies #-}
|
|
|
|
> {-# LANGUAGE DeriveGeneric #-}
|
|
|
|
> {-# LANGUAGE TypeOperators #-}
|
|
|
|
> {-# LANGUAGE OverloadedStrings #-}
|
|
|
|
>
|
|
|
|
> import Data.Aeson
|
|
|
|
> import Data.Monoid
|
|
|
|
> import Data.Proxy
|
|
|
|
> import Data.Text
|
|
|
|
> import GHC.Generics
|
|
|
|
> import Network.Wai
|
|
|
|
> import Network.Wai.Handler.Warp
|
|
|
|
>
|
|
|
|
> import Servant
|
|
|
|
>
|
|
|
|
> -- * Example
|
|
|
|
>
|
|
|
|
> -- | A greet message data type
|
|
|
|
> newtype Greet = Greet { msg :: Text }
|
|
|
|
> deriving (Generic, Show)
|
|
|
|
>
|
|
|
|
> instance FromJSON Greet
|
|
|
|
> instance ToJSON Greet
|
|
|
|
>
|
|
|
|
> -- API specification
|
|
|
|
> type TestApi =
|
|
|
|
> -- GET /hello/:name?capital={true, false}
|
|
|
|
-- returns a Greet as JSON
|
|
|
|
> "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get Greet
|
|
|
|
>
|
|
|
|
> -- POST /greet with a Greet as JSON in the request body,
|
|
|
|
> -- returns a Greet as JSON
|
|
|
|
> :<|> "greet" :> ReqBody Greet :> Post Greet
|
|
|
|
>
|
|
|
|
> -- DELETE /greet/:greetid
|
|
|
|
> :<|> "greet" :> Capture "greetid" Text :> Delete
|
|
|
|
>
|
|
|
|
> testApi :: Proxy TestApi
|
|
|
|
> testApi = Proxy
|
|
|
|
>
|
|
|
|
> -- Server-side handlers.
|
|
|
|
> --
|
|
|
|
> -- There's one handler per endpoint, which, just like in the type
|
|
|
|
> -- that represents the API, are glued together using :<|>.
|
|
|
|
> --
|
|
|
|
> -- Each handler runs in the 'EitherT (Int, String) IO' monad.
|
|
|
|
> server :: Server TestApi
|
|
|
|
> server = helloH :<|> postGreetH :<|> deleteGreetH
|
|
|
|
>
|
|
|
|
> where helloH name Nothing = helloH name (Just False)
|
|
|
|
> helloH name (Just False) = return . Greet $ "Hello, " <> name
|
|
|
|
> helloH name (Just True) = return . Greet . toUpper $ "Hello, " <> name
|
|
|
|
>
|
|
|
|
> postGreetH greet = return greet
|
|
|
|
>
|
|
|
|
> deleteGreetH _ = return ()
|
|
|
|
>
|
|
|
|
> -- Turn the server into a WAI app. 'serve' is provided by servant,
|
|
|
|
> -- more precisely by the Servant.Server module.
|
|
|
|
> test :: Application
|
|
|
|
> test = serve testApi server
|
|
|
|
>
|
|
|
|
> -- Run the server.
|
|
|
|
> --
|
|
|
|
> -- 'run' comes from Network.Wai.Handler.Warp
|
|
|
|
> runTestServer :: Port -> IO ()
|
|
|
|
> runTestServer port = run port test
|
|
|
|
>
|
|
|
|
> -- Put this all to work!
|
|
|
|
> main :: IO ()
|
|
|
|
> main = runTestServer 8001
|
|
|
|
homepage: http://haskell-servant.github.io/
|
|
|
|
Bug-reports: http://github.com/haskell-servant/servant/issues
|
2014-10-21 15:25:34 +02:00
|
|
|
license: BSD3
|
|
|
|
license-file: LICENSE
|
2014-10-29 18:51:09 +01:00
|
|
|
author: Alp Mestanogullari, Sönke Hahn, Julian K. Arni
|
2014-10-21 15:25:34 +02:00
|
|
|
maintainer: alpmestan@gmail.com
|
2014-10-30 08:47:54 +01:00
|
|
|
copyright: 2014 Zalora South East Asia Pte Ltd
|
2014-10-21 15:25:34 +02:00
|
|
|
category: Web
|
|
|
|
build-type: Simple
|
|
|
|
cabal-version: >=1.10
|
2014-11-22 13:54:24 +01:00
|
|
|
tested-with: GHC >= 7.8
|
2014-12-08 10:56:02 +01:00
|
|
|
source-repository head
|
|
|
|
type: git
|
|
|
|
location: http://github.com/haskell-servant/servant.git
|
2014-10-21 15:25:34 +02:00
|
|
|
|
|
|
|
library
|
2014-10-25 01:27:39 +02:00
|
|
|
exposed-modules:
|
|
|
|
Servant
|
|
|
|
Servant.API
|
2014-11-07 04:58:41 +01:00
|
|
|
Servant.API.Alternative
|
2014-10-25 01:27:39 +02:00
|
|
|
Servant.API.Capture
|
2014-10-28 09:14:10 +01:00
|
|
|
Servant.API.Delete
|
2014-10-25 01:27:39 +02:00
|
|
|
Servant.API.Get
|
|
|
|
Servant.API.Post
|
2014-10-28 09:17:28 +01:00
|
|
|
Servant.API.Put
|
2014-11-07 04:58:41 +01:00
|
|
|
Servant.API.QueryParam
|
2014-10-27 11:24:20 +01:00
|
|
|
Servant.API.Raw
|
2014-11-07 04:58:41 +01:00
|
|
|
Servant.API.ReqBody
|
2014-10-25 01:27:39 +02:00
|
|
|
Servant.API.Sub
|
2014-11-07 11:57:41 +01:00
|
|
|
Servant.Common.Text
|
2014-11-25 16:35:56 +01:00
|
|
|
Servant.QQ
|
2014-11-07 04:58:41 +01:00
|
|
|
Servant.Server
|
2014-11-07 09:58:53 +01:00
|
|
|
Servant.Utils.Links
|
2014-11-12 09:02:40 +01:00
|
|
|
Servant.Utils.StaticFiles
|
2014-10-21 15:25:34 +02:00
|
|
|
build-depends:
|
2014-10-28 05:55:07 +01:00
|
|
|
base >=4.7 && <5
|
2014-10-21 15:25:34 +02:00
|
|
|
, aeson
|
2014-10-31 13:29:00 +01:00
|
|
|
, attoparsec
|
2014-10-24 13:36:19 +02:00
|
|
|
, bytestring
|
2014-11-27 18:28:01 +01:00
|
|
|
, either
|
2014-10-21 15:25:34 +02:00
|
|
|
, http-types
|
2014-11-05 13:03:57 +01:00
|
|
|
, network-uri >= 2.6
|
2014-11-12 11:34:33 +01:00
|
|
|
, parsec
|
2014-10-29 13:10:04 +01:00
|
|
|
, safe
|
2014-11-27 18:28:01 +01:00
|
|
|
, split
|
|
|
|
, string-conversions
|
|
|
|
, system-filepath
|
2014-10-28 13:22:11 +01:00
|
|
|
, template-haskell
|
2014-10-21 15:25:34 +02:00
|
|
|
, text
|
2014-11-27 18:28:01 +01:00
|
|
|
, transformers
|
|
|
|
, wai
|
|
|
|
, wai-app-static
|
|
|
|
, warp
|
2014-10-25 01:27:39 +02:00
|
|
|
hs-source-dirs: src
|
|
|
|
default-language: Haskell2010
|
2014-12-08 10:56:02 +01:00
|
|
|
ghc-options: -Wall
|
2014-10-25 01:27:39 +02:00
|
|
|
|
|
|
|
executable greet
|
|
|
|
main-is: greet.hs
|
|
|
|
hs-source-dirs: example
|
2014-12-08 10:56:02 +01:00
|
|
|
ghc-options: -Wall
|
2014-10-25 01:27:39 +02:00
|
|
|
default-language: Haskell2010
|
|
|
|
build-depends:
|
|
|
|
base
|
|
|
|
, servant
|
|
|
|
, aeson
|
|
|
|
, warp
|
|
|
|
, wai
|
|
|
|
, text
|
2014-10-27 07:24:23 +01:00
|
|
|
|
|
|
|
test-suite spec
|
|
|
|
type: exitcode-stdio-1.0
|
|
|
|
ghc-options:
|
2014-11-13 12:56:44 +01:00
|
|
|
-Wall -fno-warn-name-shadowing -fno-warn-missing-signatures
|
2014-10-27 07:24:23 +01:00
|
|
|
default-language: Haskell2010
|
2014-10-28 09:04:27 +01:00
|
|
|
hs-source-dirs: test
|
2014-10-27 07:24:23 +01:00
|
|
|
main-is: Spec.hs
|
|
|
|
build-depends:
|
|
|
|
base == 4.*
|
|
|
|
, aeson
|
|
|
|
, bytestring
|
2014-11-12 09:02:40 +01:00
|
|
|
, directory
|
2014-10-27 07:24:23 +01:00
|
|
|
, either
|
|
|
|
, exceptions
|
2014-11-14 09:14:08 +01:00
|
|
|
, hspec == 2.*
|
2014-10-27 07:24:23 +01:00
|
|
|
, hspec-wai
|
|
|
|
, http-types
|
2014-10-30 12:29:03 +01:00
|
|
|
, network >= 2.6
|
2014-10-31 14:50:57 +01:00
|
|
|
, QuickCheck
|
2014-11-12 11:34:33 +01:00
|
|
|
, parsec
|
2014-10-28 09:04:27 +01:00
|
|
|
, servant
|
2014-10-27 07:24:23 +01:00
|
|
|
, string-conversions
|
2014-11-12 06:21:59 +01:00
|
|
|
, temporary
|
2014-10-27 07:24:23 +01:00
|
|
|
, text
|
|
|
|
, transformers
|
|
|
|
, wai
|
|
|
|
, wai-extra
|
2014-10-30 12:29:03 +01:00
|
|
|
, warp
|