on master help sign in
Replace all occurances of () with NoContent
05379edArian van Putten
servant-docs/example/greet.hs+2−2
@@ -81,7 +81,7 @@ type TestApi =
81 :<|> "greet" :> ReqBody '[JSON] Greet :> Post '[JSON] (Headers '[Header "X-Example" Int] Greet)
81 :<|> "greet" :> ReqBody '[JSON] Greet :> Post '[JSON] (Headers '[Header "X-Example" Int] Greet)
82
82
83 -- DELETE /greet/:greetid
83 -- DELETE /greet/:greetid
84− :<|> "greet" :> Capture "greetid" Text :> Delete '[JSON] ()
84+ :<|> "greet" :> Capture "greetid" Text :> Delete '[JSON] NoContent
85
85
86testApi :: Proxy TestApi
86testApi :: Proxy TestApi
87testApi = Proxy
87testApi = Proxy
@@ -91,7 +91,7 @@ testApi = Proxy
91-- notes.
91-- notes.
92extra :: ExtraInfo TestApi
92extra :: ExtraInfo TestApi
93extra =
93extra =
94− extraInfo (Proxy :: Proxy ("greet" :> Capture "greetid" Text :> Delete '[JSON] ())) $
94+ extraInfo (Proxy :: Proxy ("greet" :> Capture "greetid" Text :> Delete '[JSON] NoContent)) $
95 defAction & headers <>~ ["unicorns"]
95 defAction & headers <>~ ["unicorns"]
96 & notes <>~ [ DocNote "Title" ["This is some text"]
96 & notes <>~ [ DocNote "Title" ["This is some text"]
97 , DocNote "Second secton" ["And some more"]
97 , DocNote "Second secton" ["And some more"]
servant-docs/src/Servant/Docs/Internal.hs+1−1
@@ -833,7 +833,7 @@ instance (ToAuthInfo (BasicAuth realm usr), HasDocs api) => HasDocs (BasicAuth r
833 action' = over authInfo (|> toAuthInfo authProxy) action
833 action' = over authInfo (|> toAuthInfo authProxy) action
834
834
835-- ToSample instances for simple types
835-- ToSample instances for simple types
836−instance ToSample ()
836+instance ToSample NoContent
837instance ToSample Bool
837instance ToSample Bool
838instance ToSample Ordering
838instance ToSample Ordering
839
839
servant-foreign/src/Servant/Foreign/Internal.hs+6−6
@@ -169,11 +169,11 @@ type family Elem (a :: *) (ls::[*]) :: Constraint where
169-- > getEndpoints api = listFromAPI (Proxy :: Proxy LangX) (Proxy :: Proxy Text) api
169-- > getEndpoints api = listFromAPI (Proxy :: Proxy LangX) (Proxy :: Proxy Text) api
170--
170--
171-- > -- If language __X__ is dynamically typed then you can use
171-- > -- If language __X__ is dynamically typed then you can use
172−-- > -- a predefined NoTypes parameter with the () output type:
172+-- > -- a predefined NoTypes parameter with the NoContent output type:
173--
173--
174−-- > getEndpoints :: (HasForeign NoTypes () api, GenerateList Text (Foreign () api))
174+-- > getEndpoints :: (HasForeign NoTypes NoContent api, GenerateList Text (Foreign NoContent api))
175−-- > => Proxy api -> [Req ()]
175+-- > => Proxy api -> [Req NoContent]
176−-- > getEndpoints api = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy ()) api
176+-- > getEndpoints api = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) api
177-- >
177-- >
178--
178--
179class HasForeignType lang ftype a where
179class HasForeignType lang ftype a where
@@ -181,8 +181,8 @@ class HasForeignType lang ftype a where
181
181
182data NoTypes
182data NoTypes
183
183
184−instance HasForeignType NoTypes () ftype where
184+instance HasForeignType NoTypes NoContent ftype where
185− typeFor _ _ _ = ()
185+ typeFor _ _ _ = NoContent
186
186
187class HasForeign lang ftype (api :: *) where
187class HasForeign lang ftype (api :: *) where
188 type Foreign ftype api :: *
188 type Foreign ftype api :: *
servant-foreign/test/Servant/ForeignSpec.hs+4−4
@@ -26,7 +26,7 @@ camelCaseSpec = describe "camelCase" $ do
26
26
27data LangX
27data LangX
28
28
29−instance HasForeignType LangX String () where
29+instance HasForeignType LangX String NoContent where
30 typeFor _ _ _ = "voidX"
30 typeFor _ _ _ = "voidX"
31
31
32instance HasForeignType LangX String Int where
32instance HasForeignType LangX String Int where
@@ -43,9 +43,9 @@ instance OVERLAPPABLE_ HasForeignType LangX String a => HasForeignType LangX Str
43
43
44type TestApi
44type TestApi
45 = "test" :> Header "header" [String] :> QueryFlag "flag" :> Get '[JSON] Int
45 = "test" :> Header "header" [String] :> QueryFlag "flag" :> Get '[JSON] Int
46− :<|> "test" :> QueryParam "param" Int :> ReqBody '[JSON] [String] :> Post '[JSON] ()
46+ :<|> "test" :> QueryParam "param" Int :> ReqBody '[JSON] [String] :> Post '[JSON] NoContent
47− :<|> "test" :> QueryParams "params" Int :> ReqBody '[JSON] String :> Put '[JSON] ()
47+ :<|> "test" :> QueryParams "params" Int :> ReqBody '[JSON] String :> Put '[JSON] NoContent
48− :<|> "test" :> Capture "id" Int :> Delete '[JSON] ()
48+ :<|> "test" :> Capture "id" Int :> Delete '[JSON] NoContent
49
49
50testApi :: [Req String]
50testApi :: [Req String]
51testApi = listFromAPI (Proxy :: Proxy LangX) (Proxy :: Proxy String) (Proxy :: Proxy TestApi)
51testApi = listFromAPI (Proxy :: Proxy LangX) (Proxy :: Proxy String) (Proxy :: Proxy TestApi)
servant-js/servant-js.cabal+1
@@ -46,6 +46,7 @@ library
46 , charset >= 0.3
46 , charset >= 0.3
47 , lens >= 4
47 , lens >= 4
48 , servant-foreign == 0.7.*
48 , servant-foreign == 0.7.*
49+ , servant == 0.7.*
49 , text >= 1.2 && < 1.3
50 , text >= 1.2 && < 1.3
50
51
51 hs-source-dirs: src
52 hs-source-dirs: src
servant-js/src/Servant/JS.hs+6−5
@@ -118,6 +118,7 @@ import Prelude hiding (writeFile)
118import Data.Proxy
118import Data.Proxy
119import Data.Text
119import Data.Text
120import Data.Text.IO (writeFile)
120import Data.Text.IO (writeFile)
121+import Servant.API.ContentTypes
121import Servant.JS.Angular
122import Servant.JS.Angular
122import Servant.JS.Axios
123import Servant.JS.Axios
123import Servant.JS.Internal
124import Servant.JS.Internal
@@ -128,22 +129,22 @@ import Servant.Foreign (listFromAPI)
128-- | Generate the data necessary to generate javascript code
129-- | Generate the data necessary to generate javascript code
129-- for all the endpoints of an API, as ':<|>'-separated values
130-- for all the endpoints of an API, as ':<|>'-separated values
130-- of type 'AjaxReq'.
131-- of type 'AjaxReq'.
131−javascript :: HasForeign NoTypes () api => Proxy api -> Foreign () api
132+javascript :: HasForeign NoTypes NoContent api => Proxy api -> Foreign NoContent api
132−javascript p = foreignFor (Proxy :: Proxy NoTypes) (Proxy :: Proxy ()) p defReq
133+javascript p = foreignFor (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) p defReq
133
134
134-- | Directly generate all the javascript functions for your API
135-- | Directly generate all the javascript functions for your API
135-- from a 'Proxy' for your API type. You can then write it to
136-- from a 'Proxy' for your API type. You can then write it to
136-- a file or integrate it in a page, for example.
137-- a file or integrate it in a page, for example.
137−jsForAPI :: (HasForeign NoTypes () api, GenerateList () (Foreign () api))
138+jsForAPI :: (HasForeign NoTypes NoContent api, GenerateList NoContent (Foreign NoContent api))
138 => Proxy api -- ^ proxy for your API type
139 => Proxy api -- ^ proxy for your API type
139 -> JavaScriptGenerator -- ^ js code generator to use (angular, vanilla js, jquery, others)
140 -> JavaScriptGenerator -- ^ js code generator to use (angular, vanilla js, jquery, others)
140 -> Text -- ^ a text that you can embed in your pages or write to a file
141 -> Text -- ^ a text that you can embed in your pages or write to a file
141−jsForAPI p gen = gen (listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy ()) p)
142+jsForAPI p gen = gen (listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) p)
142
143
143-- | Directly generate all the javascript functions for your API
144-- | Directly generate all the javascript functions for your API
144-- from a 'Proxy' for your API type using the given generator
145-- from a 'Proxy' for your API type using the given generator
145-- and write the resulting code to a file at the given path.
146-- and write the resulting code to a file at the given path.
146−writeJSForAPI :: (HasForeign NoTypes () api, GenerateList () (Foreign () api))
147+writeJSForAPI :: (HasForeign NoTypes NoContent api, GenerateList NoContent (Foreign NoContent api))
147 => Proxy api -- ^ proxy for your API type
148 => Proxy api -- ^ proxy for your API type
148 -> JavaScriptGenerator -- ^ js code generator to use (angular, vanilla js, jquery, others)
149 -> JavaScriptGenerator -- ^ js code generator to use (angular, vanilla js, jquery, others)
149 -> FilePath -- ^ path to the file you want to write the resulting javascript code into
150 -> FilePath -- ^ path to the file you want to write the resulting javascript code into
servant-js/src/Servant/JS/Internal.hs+2−2
@@ -54,12 +54,12 @@ import qualified Data.Text as T
54import Data.Text (Text)
54import Data.Text (Text)
55import Servant.Foreign
55import Servant.Foreign
56
56
57−type AjaxReq = Req ()
57+type AjaxReq = Req NoContent
58
58
59-- A 'JavascriptGenerator' just takes the data found in the API type
59-- A 'JavascriptGenerator' just takes the data found in the API type
60-- for each endpoint and generates Javascript code in a Text. Several
60-- for each endpoint and generates Javascript code in a Text. Several
61-- generators are available in this package.
61-- generators are available in this package.
62−type JavaScriptGenerator = [Req ()] -> Text
62+type JavaScriptGenerator = [Req NoContent] -> Text
63
63
64-- | This structure is used by specific implementations to let you
64-- | This structure is used by specific implementations to let you
65-- customize the output
65-- customize the output
servant-js/test/Servant/JSSpec.hs+3−2
@@ -21,6 +21,7 @@ import Prelude.Compat
21import Test.Hspec hiding (shouldContain, shouldNotContain)
21import Test.Hspec hiding (shouldContain, shouldNotContain)
22
22
23import Servant.API.Internal.Test.ComprehensiveAPI
23import Servant.API.Internal.Test.ComprehensiveAPI
24+import Servant.API.ContentTypes
24import Servant.JS
25import Servant.JS
25import Servant.JS.Internal
26import Servant.JS.Internal
26import qualified Servant.JS.Angular as NG
27import qualified Servant.JS.Angular as NG
@@ -105,7 +106,7 @@ a `shouldNotContain` b = shouldNotSatisfy a (T.isInfixOf b)
105
106
106axiosSpec :: Spec
107axiosSpec :: Spec
107axiosSpec = describe specLabel $ do
108axiosSpec = describe specLabel $ do
108− let reqList = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy ()) (Proxy :: Proxy TestAPI)
109+ let reqList = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) (Proxy :: Proxy TestAPI)
109 it "should add withCredentials when needed" $ do
110 it "should add withCredentials when needed" $ do
110 let jsText = genJS withCredOpts $ reqList
111 let jsText = genJS withCredOpts $ reqList
111 output jsText
112 output jsText
@@ -129,7 +130,7 @@ axiosSpec = describe specLabel $ do
129
130
130angularSpec :: TestNames -> Spec
131angularSpec :: TestNames -> Spec
131angularSpec test = describe specLabel $ do
132angularSpec test = describe specLabel $ do
132− let reqList = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy ()) (Proxy :: Proxy TestAPI)
133+ let reqList = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) (Proxy :: Proxy TestAPI)
133 it "should implement a service globally" $ do
134 it "should implement a service globally" $ do
134 let jsText = genJS reqList
135 let jsText = genJS reqList
135 output jsText
136 output jsText
servant-js/test/Servant/JSSpec/CustomHeaders.hs+13−12
@@ -16,6 +16,7 @@ import Data.Monoid
16import Data.Proxy
16import Data.Proxy
17import Data.Text (pack)
17import Data.Text (pack)
18import GHC.TypeLits
18import GHC.TypeLits
19+import Servant.API.ContentTypes
19import Servant.JS.Internal
20import Servant.JS.Internal
20
21
21-- | This is a hypothetical combinator that fetches an Authorization header.
22-- | This is a hypothetical combinator that fetches an Authorization header.
@@ -23,13 +24,13 @@ import Servant.JS.Internal
23-- using -- Basic, Digest, whatever.
24-- using -- Basic, Digest, whatever.
24data Authorization (sym :: Symbol) a
25data Authorization (sym :: Symbol) a
25
26
26−instance (KnownSymbol sym, HasForeign lang () api)
27+instance (KnownSymbol sym, HasForeign lang NoContent api)
27− => HasForeign lang () (Authorization sym a :> api) where
28+ => HasForeign lang NoContent (Authorization sym a :> api) where
28− type Foreign () (Authorization sym a :> api) = Foreign () api
29+ type Foreign NoContent (Authorization sym a :> api) = Foreign NoContent api
29
30
30 foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $
31 foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $
31 req & reqHeaders <>~
32 req & reqHeaders <>~
32− [ ReplaceHeaderArg (Arg "Authorization" ())
33+ [ ReplaceHeaderArg (Arg "Authorization" NoContent)
33 $ tokenType (pack . symbolVal $ (Proxy :: Proxy sym)) ]
34 $ tokenType (pack . symbolVal $ (Proxy :: Proxy sym)) ]
34 where
35 where
35 tokenType t = t <> " {Authorization}"
36 tokenType t = t <> " {Authorization}"
@@ -37,23 +38,23 @@ instance (KnownSymbol sym, HasForeign lang () api)
37-- | This is a combinator that fetches an X-MyLovelyHorse header.
38-- | This is a combinator that fetches an X-MyLovelyHorse header.
38data MyLovelyHorse a
39data MyLovelyHorse a
39
40
40−instance (HasForeign lang () api)
41+instance (HasForeign lang NoContent api)
41− => HasForeign lang () (MyLovelyHorse a :> api) where
42+ => HasForeign lang NoContent (MyLovelyHorse a :> api) where
42− type Foreign () (MyLovelyHorse a :> api) = Foreign () api
43+ type Foreign NoContent (MyLovelyHorse a :> api) = Foreign NoContent api
43
44
44 foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $
45 foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $
45− req & reqHeaders <>~ [ ReplaceHeaderArg (Arg "X-MyLovelyHorse" ()) tpl ]
46+ req & reqHeaders <>~ [ ReplaceHeaderArg (Arg "X-MyLovelyHorse" NoContent) tpl ]
46 where
47 where
47 tpl = "I am good friends with {X-MyLovelyHorse}"
48 tpl = "I am good friends with {X-MyLovelyHorse}"
48
49
49-- | This is a combinator that fetches an X-WhatsForDinner header.
50-- | This is a combinator that fetches an X-WhatsForDinner header.
50data WhatsForDinner a
51data WhatsForDinner a
51
52
52−instance (HasForeign lang () api)
53+instance (HasForeign lang NoContent api)
53− => HasForeign lang () (WhatsForDinner a :> api) where
54+ => HasForeign lang NoContent (WhatsForDinner a :> api) where
54− type Foreign () (WhatsForDinner a :> api) = Foreign () api
55+ type Foreign NoContent (WhatsForDinner a :> api) = Foreign NoContent api
55
56
56 foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $
57 foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $
57− req & reqHeaders <>~ [ ReplaceHeaderArg (Arg "X-WhatsForDinner" ()) tpl ]
58+ req & reqHeaders <>~ [ ReplaceHeaderArg (Arg "X-WhatsForDinner" NoContent) tpl ]
58 where
59 where
59 tpl = "I would like {X-WhatsForDinner} with a cherry on top."
60 tpl = "I would like {X-WhatsForDinner} with a cherry on top."
servant-mock/src/Servant/Mock.hs+3
@@ -180,3 +180,6 @@ instance Arbitrary (HList '[]) where
180instance (Arbitrary a, Arbitrary (HList hs))
180instance (Arbitrary a, Arbitrary (HList hs))
181 => Arbitrary (HList (Header h a ': hs)) where
181 => Arbitrary (HList (Header h a ': hs)) where
182 arbitrary = HCons <$> fmap Header arbitrary <*> arbitrary
182 arbitrary = HCons <$> fmap Header arbitrary <*> arbitrary
183+
184+instance Arbitrary NoContent where
185+ arbitrary = pure NoContent
servant-server/example/greet.hs+2−2
@@ -34,7 +34,7 @@ type TestApi =
34 :<|> "greet" :> ReqBody '[JSON] Greet :> Post '[JSON] Greet
34 :<|> "greet" :> ReqBody '[JSON] Greet :> Post '[JSON] Greet
35
35
36 -- DELETE /greet/:greetid
36 -- DELETE /greet/:greetid
37− :<|> "greet" :> Capture "greetid" Text :> Delete '[JSON] ()
37+ :<|> "greet" :> Capture "greetid" Text :> Delete '[JSON] NoContent
38
38
39testApi :: Proxy TestApi
39testApi :: Proxy TestApi
40testApi = Proxy
40testApi = Proxy
@@ -54,7 +54,7 @@ server = helloH :<|> postGreetH :<|> deleteGreetH
54
54
55 postGreetH greet = return greet
55 postGreetH greet = return greet
56
56
57− deleteGreetH _ = return ()
57+ deleteGreetH _ = return NoContent
58
58
59-- Turn the server into a WAI app. 'serve' is provided by servant,
59-- Turn the server into a WAI app. 'serve' is provided by servant,
60-- more precisely by the Servant.Server module.
60-- more precisely by the Servant.Server module.
servant-server/src/Servant/Server.hs+1−1
@@ -147,7 +147,7 @@ serveWithContext p context server =
147-- For the following API
147-- For the following API
148--
148--
149-- > type API =
149-- > type API =
150−-- > "a" :> "d" :> Get '[JSON] ()
150+-- > "a" :> "d" :> Get '[JSON] NoContent
151-- > :<|> "b" :> Capture "x" Int :> Get '[JSON] Bool
151-- > :<|> "b" :> Capture "x" Int :> Get '[JSON] Bool
152-- > :<|> "c" :> Put '[JSON] Bool
152-- > :<|> "c" :> Put '[JSON] Bool
153-- > :<|> "a" :> "e" :> Get '[JSON] Int
153-- > :<|> "a" :> "e" :> Get '[JSON] Int
servant-server/test/Servant/Server/RouterSpec.hs+1−1
@@ -74,7 +74,7 @@ makeTrivialRouter :: (HasServer layout '[]) => Proxy layout -> Router ()
74makeTrivialRouter p =
74makeTrivialRouter p =
75 route p EmptyContext (emptyDelayed (FailFatal err501))
75 route p EmptyContext (emptyDelayed (FailFatal err501))
76
76
77−type End = Get '[JSON] ()
77+type End = Get '[JSON] NoContent
78
78
79-- The latter version looks more efficient,
79-- The latter version looks more efficient,
80-- but the former should be compiled to the
80-- but the former should be compiled to the
servant-server/test/Servant/ServerSpec.hs+11−7
@@ -340,19 +340,23 @@ reqBodySpec = describe "Servant.API.ReqBody" $ do
340-- * headerSpec {{{
340-- * headerSpec {{{
341------------------------------------------------------------------------------
341------------------------------------------------------------------------------
342
342
343−type HeaderApi a = Header "MyHeader" a :> Delete '[JSON] ()
343+type HeaderApi a = Header "MyHeader" a :> Delete '[JSON] NoContent
344headerApi :: Proxy (HeaderApi a)
344headerApi :: Proxy (HeaderApi a)
345headerApi = Proxy
345headerApi = Proxy
346
346
347headerSpec :: Spec
347headerSpec :: Spec
348headerSpec = describe "Servant.API.Header" $ do
348headerSpec = describe "Servant.API.Header" $ do
349
349
350− let expectsInt :: Maybe Int -> Handler ()
350+ let expectsInt :: Maybe Int -> Handler NoContent
351+ expectsInt (Just x) = do
351− expectsInt (Just x) = when (x /= 5) $ error "Expected 5"
352+ when (x /= 5) $ error "Expected 5"
353+ return NoContent
352 expectsInt Nothing = error "Expected an int"
354 expectsInt Nothing = error "Expected an int"
353
355
354− let expectsString :: Maybe String -> Handler ()
356+ let expectsString :: Maybe String -> Handler NoContent
357+ expectsString (Just x) = do
355− expectsString (Just x) = when (x /= "more from you") $ error "Expected more from you"
358+ when (x /= "more from you") $ error "Expected more from you"
359+ return NoContent
356 expectsString Nothing = error "Expected a string"
360 expectsString Nothing = error "Expected a string"
357
361
358 with (return (serve headerApi expectsInt)) $ do
362 with (return (serve headerApi expectsInt)) $ do
@@ -410,7 +414,7 @@ type AlternativeApi =
410 :<|> "foo" :> Get '[PlainText] T.Text
414 :<|> "foo" :> Get '[PlainText] T.Text
411 :<|> "bar" :> Post '[JSON] Animal
415 :<|> "bar" :> Post '[JSON] Animal
412 :<|> "bar" :> Put '[JSON] Animal
416 :<|> "bar" :> Put '[JSON] Animal
413− :<|> "bar" :> Delete '[JSON] ()
417+ :<|> "bar" :> Delete '[JSON] NoContent
414
418
415alternativeApi :: Proxy AlternativeApi
419alternativeApi :: Proxy AlternativeApi
416alternativeApi = Proxy
420alternativeApi = Proxy
@@ -422,7 +426,7 @@ alternativeServer =
422 :<|> return "a string"
426 :<|> return "a string"
423 :<|> return jerry
427 :<|> return jerry
424 :<|> return jerry
428 :<|> return jerry
425− :<|> return ()
429+ :<|> return NoContent
426
430
427alternativeSpec :: Spec
431alternativeSpec :: Spec
428alternativeSpec = do
432alternativeSpec = do
servant/src/Servant/API/ContentTypes.hs+1−1
@@ -319,7 +319,7 @@ instance MimeRender OctetStream BS.ByteString where
319
319
320-- | A type for responses without content-body.
320-- | A type for responses without content-body.
321data NoContent = NoContent
321data NoContent = NoContent
322− deriving (Show, Eq, Read)
322+ deriving (Show, Eq, Read, Generic)
323
323
324
324
325--------------------------------------------------------------------------
325--------------------------------------------------------------------------
servant/src/Servant/API/Internal/Test/ComprehensiveAPI.hs+3−3
@@ -10,7 +10,7 @@ import Data.Proxy
10
10
11import Servant.API
11import Servant.API
12
12
13−type GET = Get '[JSON] ()
13+type GET = Get '[JSON] NoContent
14
14
15type ComprehensiveAPI =
15type ComprehensiveAPI =
16 GET :<|>
16 GET :<|>
@@ -25,10 +25,10 @@ type ComprehensiveAPI =
25-- Raw :<|>
25-- Raw :<|>
26 RemoteHost :> GET :<|>
26 RemoteHost :> GET :<|>
27 ReqBody '[JSON] Int :> GET :<|>
27 ReqBody '[JSON] Int :> GET :<|>
28− Get '[JSON] (Headers '[Header "foo" Int] ()) :<|>
28+ Get '[JSON] (Headers '[Header "foo" Int] NoContent) :<|>
29 "foo" :> GET :<|>
29 "foo" :> GET :<|>
30 Vault :> GET :<|>
30 Vault :> GET :<|>
31− Verb 'POST 204 '[JSON] () :<|>
31+ Verb 'POST 204 '[JSON] NoContent :<|>
32 Verb 'POST 204 '[JSON] Int :<|>
32 Verb 'POST 204 '[JSON] Int :<|>
33 WithNamedContext "foo" '[] GET
33 WithNamedContext "foo" '[] GET
34
34
servant/src/Servant/Utils/Links.hs+4−4
@@ -21,7 +21,7 @@
21-- >>>
21-- >>>
22-- >>>
22-- >>>
23-- >>> type Hello = "hello" :> Get '[JSON] Int
23-- >>> type Hello = "hello" :> Get '[JSON] Int
24−-- >>> type Bye = "bye" :> QueryParam "name" String :> Delete '[JSON] ()
24+-- >>> type Bye = "bye" :> QueryParam "name" String :> Delete '[JSON] NoContent
25-- >>> type API = Hello :<|> Bye
25-- >>> type API = Hello :<|> Bye
26-- >>> let api = Proxy :: Proxy API
26-- >>> let api = Proxy :: Proxy API
27--
27--
@@ -47,11 +47,11 @@
47-- If the API has an endpoint with parameters then we can generate links with
47-- If the API has an endpoint with parameters then we can generate links with
48-- or without those:
48-- or without those:
49--
49--
50−-- >>> let with = Proxy :: Proxy ("bye" :> QueryParam "name" String :> Delete '[JSON] ())
50+-- >>> let with = Proxy :: Proxy ("bye" :> QueryParam "name" String :> Delete '[JSON] NoContent)
51-- >>> print $ safeLink api with (Just "Hubert")
51-- >>> print $ safeLink api with (Just "Hubert")
52-- bye?name=Hubert
52-- bye?name=Hubert
53--
53--
54−-- >>> let without = Proxy :: Proxy ("bye" :> Delete '[JSON] ())
54+-- >>> let without = Proxy :: Proxy ("bye" :> Delete '[JSON] NoContent)
55-- >>> print $ safeLink api without
55-- >>> print $ safeLink api without
56-- bye
56-- bye
57--
57--
@@ -69,7 +69,7 @@
69-- Attempting to construct a link to an endpoint that does not exist in api
69-- Attempting to construct a link to an endpoint that does not exist in api
70-- will result in a type error like this:
70-- will result in a type error like this:
71--
71--
72−-- >>> let bad_link = Proxy :: Proxy ("hello" :> Delete '[JSON] ())
72+-- >>> let bad_link = Proxy :: Proxy ("hello" :> Delete '[JSON] NoContent)
73-- >>> safeLink api bad_link
73-- >>> safeLink api bad_link
74-- ...
74-- ...
75-- ...Could not deduce...
75-- ...Could not deduce...
servant/test/Servant/Utils/LinksSpec.hs+17−17
@@ -12,16 +12,16 @@ import Servant.API
12
12
13type TestApi =
13type TestApi =
14 -- Capture and query params
14 -- Capture and query params
15− "hello" :> Capture "name" String :> QueryParam "capital" Bool :> Delete '[JSON] ()
15+ "hello" :> Capture "name" String :> QueryParam "capital" Bool :> Delete '[JSON] NoContent
16
16
17 -- Flags
17 -- Flags
18− :<|> "balls" :> QueryFlag "bouncy" :> QueryFlag "fast" :> Delete '[JSON] ()
18+ :<|> "balls" :> QueryFlag "bouncy" :> QueryFlag "fast" :> Delete '[JSON] NoContent
19
19
20 -- All of the verbs
20 -- All of the verbs
21− :<|> "get" :> Get '[JSON] ()
21+ :<|> "get" :> Get '[JSON] NoContent
22− :<|> "put" :> Put '[JSON] ()
22+ :<|> "put" :> Put '[JSON] NoContent
23− :<|> "post" :> ReqBody '[JSON] 'True :> Post '[JSON] ()
23+ :<|> "post" :> ReqBody '[JSON] 'True :> Post '[JSON] NoContent
24− :<|> "delete" :> Header "ponies" String :> Delete '[JSON] ()
24+ :<|> "delete" :> Header "ponies" String :> Delete '[JSON] NoContent
25 :<|> "raw" :> Raw
25 :<|> "raw" :> Raw
26
26
27
27
@@ -38,26 +38,26 @@ shouldBeURI link expected =
38spec :: Spec
38spec :: Spec
39spec = describe "Servant.Utils.Links" $ do
39spec = describe "Servant.Utils.Links" $ do
40 it "generates correct links for capture query params" $ do
40 it "generates correct links for capture query params" $ do
41− let l1 = Proxy :: Proxy ("hello" :> Capture "name" String :> Delete '[JSON] ())
41+ let l1 = Proxy :: Proxy ("hello" :> Capture "name" String :> Delete '[JSON] NoContent)
42 apiLink l1 "hi" `shouldBeURI` "hello/hi"
42 apiLink l1 "hi" `shouldBeURI` "hello/hi"
43
43
44 let l2 = Proxy :: Proxy ("hello" :> Capture "name" String
44 let l2 = Proxy :: Proxy ("hello" :> Capture "name" String
45 :> QueryParam "capital" Bool
45 :> QueryParam "capital" Bool
46− :> Delete '[JSON] ())
46+ :> Delete '[JSON] NoContent)
47 apiLink l2 "bye" (Just True) `shouldBeURI` "hello/bye?capital=true"
47 apiLink l2 "bye" (Just True) `shouldBeURI` "hello/bye?capital=true"
48
48
49
49
50 it "generates correct links for query flags" $ do
50 it "generates correct links for query flags" $ do
51 let l1 = Proxy :: Proxy ("balls" :> QueryFlag "bouncy"
51 let l1 = Proxy :: Proxy ("balls" :> QueryFlag "bouncy"
52− :> QueryFlag "fast" :> Delete '[JSON] ())
52+ :> QueryFlag "fast" :> Delete '[JSON] NoContent)
53 apiLink l1 True True `shouldBeURI` "balls?bouncy&fast"
53 apiLink l1 True True `shouldBeURI` "balls?bouncy&fast"
54 apiLink l1 False True `shouldBeURI` "balls?fast"
54 apiLink l1 False True `shouldBeURI` "balls?fast"
55
55
56 it "generates correct links for all of the verbs" $ do
56 it "generates correct links for all of the verbs" $ do
57− apiLink (Proxy :: Proxy ("get" :> Get '[JSON] ())) `shouldBeURI` "get"
57+ apiLink (Proxy :: Proxy ("get" :> Get '[JSON] NoContent)) `shouldBeURI` "get"
58− apiLink (Proxy :: Proxy ("put" :> Put '[JSON] ())) `shouldBeURI` "put"
58+ apiLink (Proxy :: Proxy ("put" :> Put '[JSON] NoContent)) `shouldBeURI` "put"
59− apiLink (Proxy :: Proxy ("post" :> Post '[JSON] ())) `shouldBeURI` "post"
59+ apiLink (Proxy :: Proxy ("post" :> Post '[JSON] NoContent)) `shouldBeURI` "post"
60− apiLink (Proxy :: Proxy ("delete" :> Delete '[JSON] ())) `shouldBeURI` "delete"
60+ apiLink (Proxy :: Proxy ("delete" :> Delete '[JSON] NoContent)) `shouldBeURI` "delete"
61 apiLink (Proxy :: Proxy ("raw" :> Raw)) `shouldBeURI` "raw"
61 apiLink (Proxy :: Proxy ("raw" :> Raw)) `shouldBeURI` "raw"
62
62
63
63
@@ -93,9 +93,9 @@ spec = describe "Servant.Utils.Links" $ do
93-- sanity check
93-- sanity check
94-- >>> apiLink (Proxy :: Proxy AllGood)
94-- >>> apiLink (Proxy :: Proxy AllGood)
95-- get
95-- get
96−type WrongPath = "getTypo" :> Get '[JSON] ()
96+type WrongPath = "getTypo" :> Get '[JSON] NoContent
97type WrongReturnType = "get" :> Get '[JSON] Bool
97type WrongReturnType = "get" :> Get '[JSON] Bool
98−type WrongContentType = "get" :> Get '[OctetStream] ()
98+type WrongContentType = "get" :> Get '[OctetStream] NoContent
99−type WrongMethod = "get" :> Post '[JSON] ()
99+type WrongMethod = "get" :> Post '[JSON] NoContent
100type NotALink = "hello" :> ReqBody '[JSON] 'True :> Get '[JSON] Bool
100type NotALink = "hello" :> ReqBody '[JSON] 'True :> Get '[JSON] Bool
101−type AllGood = "get" :> Get '[JSON] ()
101+type AllGood = "get" :> Get '[JSON] NoContent