@@ -8,6 +8,7 @@
8{-# LANGUAGE ScopedTypeVariables #-}
8{-# LANGUAGE ScopedTypeVariables #-}
9module Servant where
9module Servant where
11+import Control.Applicative
11import Data.Aeson
12import Data.Aeson
12import Data.Monoid
13import Data.Monoid
13import Data.Proxy
14import Data.Proxy
@@ -18,6 +19,7 @@ import Network.Wai
18import Network.Wai.Handler.Warp
19import Network.Wai.Handler.Warp
19import Soenke
20import Soenke
21data Capture sym a
23data Capture sym a
23class FromText a where
25class FromText a where
@@ -47,6 +49,22 @@ instance (KnownSymbol capture, FromText a, HasServer sublayout)
48 _ -> return Nothing
50 _ -> return Nothing
52+-- * Request Body support
55+instance (FromJSON a, HasServer sublayout)
56+ => HasServer (RQBody a :> sublayout) where
58+ -- same caveat as for the Captures...
59+ type Server (RQBody a :> sublayout) =
60+ RQBody a :> (a -> Server sublayout)
62+ route Proxy (rqbody :> subserver) request = do
63+ mrqbody <- decode' <$> lazyRequestBody request
65+ Nothing -> return Nothing
66+ Just v -> route (Proxy :: Proxy sublayout) (subserver v) request
50-- * Example
68-- * Example
52type TestApi = "hello" :> Capture "name" Text :> Get Greet
70type TestApi = "hello" :> Capture "name" Text :> Get Greet