on master help sign in
rename RQBody to JsonBody everywhere
9b375b1Alp Mestanogullari
example/greet.hs+1−1
@@ -51,7 +51,7 @@ instance ToSample Greet where
51-- API specification
51-- API specification
52type TestApi =
52type TestApi =
53 "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get Greet
53 "hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get Greet
54− :<|> "greet" :> RQBody Greet :> Post Greet
54+ :<|> "greet" :> JsonBody Greet :> Post Greet
55 :<|> "delete" :> Capture "greetid" Text :> Delete
55 :<|> "delete" :> Capture "greetid" Text :> Delete
56
56
57testApi :: Proxy TestApi
57testApi :: Proxy TestApi
servant.cabal+1−1
@@ -22,11 +22,11 @@ library
22 Servant.API.Capture
22 Servant.API.Capture
23 Servant.API.Delete
23 Servant.API.Delete
24 Servant.API.Get
24 Servant.API.Get
25+ Servant.API.JsonBody
25 Servant.API.Post
26 Servant.API.Post
26 Servant.API.Put
27 Servant.API.Put
27 Servant.API.QueryParam
28 Servant.API.QueryParam
28 Servant.API.Raw
29 Servant.API.Raw
29− Servant.API.RQBody
30 Servant.API.Sub
30 Servant.API.Sub
31 Servant.API.Union
31 Servant.API.Union
32 Servant.Utils.Text
32 Servant.Utils.Text
src/Servant/API.hs+4−4
@@ -9,10 +9,10 @@ module Servant.API (
9 -- * Accessing information from the request
9 -- * Accessing information from the request
10 -- | Capturing parts of the url path as parsed values: @'Capture'@
10 -- | Capturing parts of the url path as parsed values: @'Capture'@
11 module Servant.API.Capture,
11 module Servant.API.Capture,
12+ -- | Accessing the request body as a JSON-encoded type: @'JsonBody'@
13+ module Servant.API.JsonBody,
12− -- | Retrieving parameters from the query part of the 'URI': @'QueryParam'@
14+ -- | Retrieving parameters from the query string of the 'URI': @'QueryParam'@
13 module Servant.API.QueryParam,
15 module Servant.API.QueryParam,
14− -- | Accessing the request's body: @'RQBody'@
15− module Servant.API.RQBody,
16
16
17 -- * Actual endpoints, distinguished by HTTP method
17 -- * Actual endpoints, distinguished by HTTP method
18 -- | GET requests
18 -- | GET requests
@@ -28,9 +28,9 @@ module Servant.API (
28import Servant.API.Capture
28import Servant.API.Capture
29import Servant.API.Delete
29import Servant.API.Delete
30import Servant.API.Get
30import Servant.API.Get
31+import Servant.API.JsonBody
31import Servant.API.Post
32import Servant.API.Post
32import Servant.API.Put
33import Servant.API.Put
33import Servant.API.QueryParam
34import Servant.API.QueryParam
34−import Servant.API.RQBody
35import Servant.API.Sub
35import Servant.API.Sub
36import Servant.API.Union
36import Servant.API.Union
src/Servant/API/RQBody.hs → src/Servant/API/JsonBody.hsrenamed+7−7
@@ -3,7 +3,7 @@
3{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE TypeOperators #-}
4{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE ScopedTypeVariables #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6−module Servant.API.RQBody where
6+module Servant.API.JsonBody where
7
7
8import Control.Applicative
8import Control.Applicative
9import Data.Aeson
9import Data.Aeson
@@ -15,12 +15,12 @@ import Servant.Docs
15import Servant.Server
15import Servant.Server
16
16
17-- * Request Body support
17-- * Request Body support
18−data RQBody a
18+data JsonBody a
19
19
20instance (FromJSON a, HasServer sublayout)
20instance (FromJSON a, HasServer sublayout)
21− => HasServer (RQBody a :> sublayout) where
21+ => HasServer (JsonBody a :> sublayout) where
22
22
23− type Server (RQBody a :> sublayout) =
23+ type Server (JsonBody a :> sublayout) =
24 a -> Server sublayout
24 a -> Server sublayout
25
25
26 route Proxy subserver request respond = do
26 route Proxy subserver request respond = do
@@ -30,9 +30,9 @@ instance (FromJSON a, HasServer sublayout)
30 Just v -> route (Proxy :: Proxy sublayout) (subserver v) request respond
30 Just v -> route (Proxy :: Proxy sublayout) (subserver v) request respond
31
31
32instance (ToJSON a, HasClient sublayout)
32instance (ToJSON a, HasClient sublayout)
33− => HasClient (RQBody a :> sublayout) where
33+ => HasClient (JsonBody a :> sublayout) where
34
34
35− type Client (RQBody a :> sublayout) =
35+ type Client (JsonBody a :> sublayout) =
36 a -> Client sublayout
36 a -> Client sublayout
37
37
38 clientWithRoute Proxy req body =
38 clientWithRoute Proxy req body =
@@ -40,7 +40,7 @@ instance (ToJSON a, HasClient sublayout)
40 setRQBody (encode body) req
40 setRQBody (encode body) req
41
41
42instance (ToSample a, HasDocs sublayout)
42instance (ToSample a, HasDocs sublayout)
43− => HasDocs (RQBody a :> sublayout) where
43+ => HasDocs (JsonBody a :> sublayout) where
44
44
45 docsFor Proxy (endpoint, action) =
45 docsFor Proxy (endpoint, action) =
46 docsFor sublayoutP (endpoint, action')
46 docsFor sublayoutP (endpoint, action')
test/Servant/ServerSpec.hs+3−3
@@ -22,10 +22,10 @@ import Test.Hspec.Wai
22
22
23import Servant.API.Capture
23import Servant.API.Capture
24import Servant.API.Get
24import Servant.API.Get
25+import Servant.API.JsonBody
25import Servant.API.Post
26import Servant.API.Post
26import Servant.API.QueryParam
27import Servant.API.QueryParam
27import Servant.API.Raw
28import Servant.API.Raw
28−import Servant.API.RQBody
29import Servant.API.Sub
29import Servant.API.Sub
30import Servant.API.Union
30import Servant.API.Union
31import Servant.Server
31import Servant.Server
@@ -141,13 +141,13 @@ queryParamSpec = do
141 }
141 }
142
142
143
143
144−type PostApi = RQBody Person :> (Post Integer)
144+type PostApi = JsonBody Person :> Post Integer
145postApi :: Proxy PostApi
145postApi :: Proxy PostApi
146postApi = Proxy
146postApi = Proxy
147
147
148postSpec :: Spec
148postSpec :: Spec
149postSpec = do
149postSpec = do
150− describe "Servant.API.Post and .RQBody" $ do
150+ describe "Servant.API.Post and .JsonBody" $ do
151 with (return (serve postApi (return . age))) $ do
151 with (return (serve postApi (return . age))) $ do
152 it "allows to POST a Person" $ do
152 it "allows to POST a Person" $ do
153 post "/" (encode alice) `shouldRespondWith` "42"{
153 post "/" (encode alice) `shouldRespondWith` "42"{