git.iko.soy/typeable/servant
on master help sign in
Remove Canonicalize
commit50b05860b760bb2897377fa967947074f50ed3da authorJulian K. Arni <jkarni@gmail.com> dateSun 3 May 2015, 01:45 (11 years ago) parentbdf6d9a
12 files changed+106−156
servant-client/CHANGELOG.md−1 servant-client/src/Servant/Client.hs+39−40 servant-client/test/Servant/ClientSpec.hs+2−2 servant-docs/CHANGELOG.md−1 servant-docs/src/Servant/Docs/Internal.hs+4−8 servant-jquery/src/Servant/JQuery.hs+3−4 servant-jquery/src/Servant/JQuery/Internal.hs+18−20 servant-server/CHANGELOG.md−1 servant-server/src/Servant/Server.hs+2−4 servant-server/src/Servant/Server/Internal.hs+38−40 servant/CHANGELOG.md−1 servant/src/Servant/API.hs−34
servant-client/CHANGELOG.md−1
@@ -7,7 +7,6 @@
77* Make the clients for `Raw` endpoints return the whole `Response` value (to be able to access response headers for example)
88* Support for PATCH
99* Make () instances expect No Content status code, and not try to decode body.
10−* `Canonicalize` API types before generating client functions for them
1110* Add support for response headers
1211
13120.2.2
servant-client/src/Servant/Client.hs+39−40
@@ -53,17 +53,16 @@ import Servant.Common.Req
5353-- > getAllBooks :: BaseUrl -> EitherT String IO [Book]
5454-- > postNewBook :: Book -> BaseUrl -> EitherT String IO Book
5555-- > (getAllBooks :<|> postNewBook) = client myApi
56−client :: HasClient (Canonicalize layout) => Proxy layout -> Client layout
57−client p = clientWithRoute (canonicalize p) defReq
56+client :: HasClient layout => Proxy layout -> Client layout
57+client p = clientWithRoute p defReq
5858
5959-- | This class lets us define how each API combinator
6060-- influences the creation of an HTTP request. It's mostly
6161-- an internal class, you can just use 'client'.
6262class HasClient layout where
63− type Client' layout :: *
64− clientWithRoute :: Proxy layout -> Req -> Client' layout
63+ type Client layout :: *
64+ clientWithRoute :: Proxy layout -> Req -> Client layout
6565
66−type Client layout = Client' (Canonicalize layout)
6766
6867-- | A client querying function for @a ':<|>' b@ will actually hand you
6968-- one function for querying @a@ and another one for querying @b@,
@@ -79,7 +78,7 @@ type Client layout = Client' (Canonicalize layout)
7978-- > postNewBook :: Book -> BaseUrl -> EitherT String IO Book
8079-- > (getAllBooks :<|> postNewBook) = client myApi
8180instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
82− type Client' (a :<|> b) = Client' a :<|> Client' b
81+ type Client (a :<|> b) = Client a :<|> Client b
8382 clientWithRoute Proxy req =
8483 clientWithRoute (Proxy :: Proxy a) req :<|>
8584 clientWithRoute (Proxy :: Proxy b) req
@@ -106,8 +105,8 @@ instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
106105instance (KnownSymbol capture, ToText a, HasClient sublayout)
107106 => HasClient (Capture capture a :> sublayout) where
108107
109− type Client' (Capture capture a :> sublayout) =
110− a -> Client' sublayout
108+ type Client (Capture capture a :> sublayout) =
109+ a -> Client sublayout
111110
112111 clientWithRoute Proxy req val =
113112 clientWithRoute (Proxy :: Proxy sublayout) $
@@ -120,7 +119,7 @@ instance (KnownSymbol capture, ToText a, HasClient sublayout)
120119-- will just require an argument that specifies the scheme, host
121120-- and port to send the request to.
122121instance HasClient Delete where
123− type Client' Delete = BaseUrl -> EitherT ServantError IO ()
122+ type Client Delete = BaseUrl -> EitherT ServantError IO ()
124123
125124 clientWithRoute Proxy req host =
126125 void $ performRequest H.methodDelete req (`elem` [200, 202, 204]) host
@@ -134,7 +133,7 @@ instance
134133 {-# OVERLAPPABLE #-}
135134#endif
136135 (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
137− type Client' (Get (ct ': cts) result) = BaseUrl -> EitherT ServantError IO result
136+ type Client (Get (ct ': cts) result) = BaseUrl -> EitherT ServantError IO result
138137 clientWithRoute Proxy req host =
139138 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203] host
140139
@@ -145,7 +144,7 @@ instance
145144 {-# OVERLAPPING #-}
146145#endif
147146 HasClient (Get (ct ': cts) ()) where
148− type Client' (Get (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
147+ type Client (Get (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
149148 clientWithRoute Proxy req host =
150149 performRequestNoBody H.methodGet req [204] host
151150
@@ -157,7 +156,7 @@ instance
157156#endif
158157 ( MimeUnrender ct a, BuildHeadersTo ls
159158 ) => HasClient (Get (ct ': cts) (Headers ls a)) where
160− type Client' (Get (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
159+ type Client (Get (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
161160 clientWithRoute Proxy req host = do
162161 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodGet req [200, 203, 204] host
163162 return $ Headers { getResponse = resp
@@ -192,8 +191,8 @@ instance
192191instance (KnownSymbol sym, ToText a, HasClient sublayout)
193192 => HasClient (Header sym a :> sublayout) where
194193
195− type Client' (Header sym a :> sublayout) =
196− Maybe a -> Client' sublayout
194+ type Client (Header sym a :> sublayout) =
195+ Maybe a -> Client sublayout
197196
198197 clientWithRoute Proxy req mval =
199198 clientWithRoute (Proxy :: Proxy sublayout) $
@@ -210,7 +209,7 @@ instance
210209 {-# OVERLAPPABLE #-}
211210#endif
212211 (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
213− type Client' (Post (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
212+ type Client (Post (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
214213
215214 clientWithRoute Proxy req uri =
216215 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPost req [200,201] uri
@@ -222,7 +221,7 @@ instance
222221 {-# OVERLAPPING #-}
223222#endif
224223 HasClient (Post (ct ': cts) ()) where
225− type Client' (Post (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
224+ type Client (Post (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
226225 clientWithRoute Proxy req host =
227226 void $ performRequestNoBody H.methodPost req [204] host
228227
@@ -234,7 +233,7 @@ instance
234233#endif
235234 ( MimeUnrender ct a, BuildHeadersTo ls
236235 ) => HasClient (Post (ct ': cts) (Headers ls a)) where
237− type Client' (Post (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
236+ type Client (Post (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
238237 clientWithRoute Proxy req host = do
239238 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPost req [200, 201] host
240239 return $ Headers { getResponse = resp
@@ -250,7 +249,7 @@ instance
250249 {-# OVERLAPPABLE #-}
251250#endif
252251 (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
253− type Client' (Put (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
252+ type Client (Put (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
254253
255254 clientWithRoute Proxy req host =
256255 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPut req [200,201] host
@@ -262,7 +261,7 @@ instance
262261 {-# OVERLAPPING #-}
263262#endif
264263 HasClient (Put (ct ': cts) ()) where
265− type Client' (Put (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
264+ type Client (Put (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
266265 clientWithRoute Proxy req host =
267266 void $ performRequestNoBody H.methodPut req [204] host
268267
@@ -274,7 +273,7 @@ instance
274273#endif
275274 ( MimeUnrender ct a, BuildHeadersTo ls
276275 ) => HasClient (Put (ct ': cts) (Headers ls a)) where
277− type Client' (Put (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
276+ type Client (Put (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
278277 clientWithRoute Proxy req host = do
279278 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPut req [200, 201] host
280279 return $ Headers { getResponse = resp
@@ -290,7 +289,7 @@ instance
290289 {-# OVERLAPPABLE #-}
291290#endif
292291 (MimeUnrender ct a) => HasClient (Patch (ct ': cts) a) where
293− type Client' (Patch (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
292+ type Client (Patch (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
294293
295294 clientWithRoute Proxy req host =
296295 snd <$> performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200,201] host
@@ -302,7 +301,7 @@ instance
302301 {-# OVERLAPPING #-}
303302#endif
304303 HasClient (Patch (ct ': cts) ()) where
305− type Client' (Patch (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
304+ type Client (Patch (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
306305 clientWithRoute Proxy req host =
307306 void $ performRequestNoBody H.methodPatch req [204] host
308307
@@ -314,7 +313,7 @@ instance
314313#endif
315314 ( MimeUnrender ct a, BuildHeadersTo ls
316315 ) => HasClient (Patch (ct ': cts) (Headers ls a)) where
317− type Client' (Patch (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
316+ type Client (Patch (ct ': cts) (Headers ls a)) = BaseUrl -> EitherT ServantError IO (Headers ls a)
318317 clientWithRoute Proxy req host = do
319318 (hdrs, resp) <- performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200, 201, 204] host
320319 return $ Headers { getResponse = resp
@@ -349,8 +348,8 @@ instance
349348instance (KnownSymbol sym, ToText a, HasClient sublayout)
350349 => HasClient (QueryParam sym a :> sublayout) where
351350
352− type Client' (QueryParam sym a :> sublayout) =
353− Maybe a -> Client' sublayout
351+ type Client (QueryParam sym a :> sublayout) =
352+ Maybe a -> Client sublayout
354353
355354 -- if mparam = Nothing, we don't add it to the query string
356355 clientWithRoute Proxy req mparam =
@@ -391,8 +390,8 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
391390instance (KnownSymbol sym, ToText a, HasClient sublayout)
392391 => HasClient (QueryParams sym a :> sublayout) where
393392
394− type Client' (QueryParams sym a :> sublayout) =
395− [a] -> Client' sublayout
393+ type Client (QueryParams sym a :> sublayout) =
394+ [a] -> Client sublayout
396395
397396 clientWithRoute Proxy req paramlist =
398397 clientWithRoute (Proxy :: Proxy sublayout) $
@@ -426,8 +425,8 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
426425instance (KnownSymbol sym, HasClient sublayout)
427426 => HasClient (QueryFlag sym :> sublayout) where
428427
429− type Client' (QueryFlag sym :> sublayout) =
430− Bool -> Client' sublayout
428+ type Client (QueryFlag sym :> sublayout) =
429+ Bool -> Client sublayout
431430
432431 clientWithRoute Proxy req flag =
433432 clientWithRoute (Proxy :: Proxy sublayout) $
@@ -465,8 +464,8 @@ instance (KnownSymbol sym, HasClient sublayout)
465464instance (KnownSymbol sym, ToText a, HasClient sublayout)
466465 => HasClient (MatrixParam sym a :> sublayout) where
467466
468− type Client' (MatrixParam sym a :> sublayout) =
469− Maybe a -> Client' sublayout
467+ type Client (MatrixParam sym a :> sublayout) =
468+ Maybe a -> Client sublayout
470469
471470 -- if mparam = Nothing, we don't add it to the query string
472471 clientWithRoute Proxy req mparam =
@@ -506,8 +505,8 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
506505instance (KnownSymbol sym, ToText a, HasClient sublayout)
507506 => HasClient (MatrixParams sym a :> sublayout) where
508507
509− type Client' (MatrixParams sym a :> sublayout) =
510− [a] -> Client' sublayout
508+ type Client (MatrixParams sym a :> sublayout) =
509+ [a] -> Client sublayout
511510
512511 clientWithRoute Proxy req paramlist =
513512 clientWithRoute (Proxy :: Proxy sublayout) $
@@ -541,8 +540,8 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
541540instance (KnownSymbol sym, HasClient sublayout)
542541 => HasClient (MatrixFlag sym :> sublayout) where
543542
544− type Client' (MatrixFlag sym :> sublayout) =
545− Bool -> Client' sublayout
543+ type Client (MatrixFlag sym :> sublayout) =
544+ Bool -> Client sublayout
546545
547546 clientWithRoute Proxy req flag =
548547 clientWithRoute (Proxy :: Proxy sublayout) $
@@ -555,9 +554,9 @@ instance (KnownSymbol sym, HasClient sublayout)
555554-- | Pick a 'Method' and specify where the server you want to query is. You get
556555-- back the full `Response`.
557556instance HasClient Raw where
558− type Client' Raw = H.Method -> BaseUrl -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
557+ type Client Raw = H.Method -> BaseUrl -> EitherT ServantError IO (Int, ByteString, MediaType, [HTTP.Header], Response ByteString)
559558
560− clientWithRoute :: Proxy Raw -> Req -> Client' Raw
559+ clientWithRoute :: Proxy Raw -> Req -> Client Raw
561560 clientWithRoute Proxy req httpMethod host = do
562561 performRequest httpMethod req (const True) host
563562
@@ -582,8 +581,8 @@ instance HasClient Raw where
582581instance (MimeRender ct a, HasClient sublayout)
583582 => HasClient (ReqBody (ct ': cts) a :> sublayout) where
584583
585− type Client' (ReqBody (ct ': cts) a :> sublayout) =
586− a -> Client' sublayout
584+ type Client (ReqBody (ct ': cts) a :> sublayout) =
585+ a -> Client sublayout
587586
588587 clientWithRoute Proxy req body =
589588 clientWithRoute (Proxy :: Proxy sublayout) $ do
@@ -592,7 +591,7 @@ instance (MimeRender ct a, HasClient sublayout)
592591
593592-- | Make the querying function append @path@ to the request path.
594593instance (KnownSymbol path, HasClient sublayout) => HasClient (path :> sublayout) where
595− type Client' (path :> sublayout) = Client' sublayout
594+ type Client (path :> sublayout) = Client sublayout
596595
597596 clientWithRoute Proxy req =
598597 clientWithRoute (Proxy :: Proxy sublayout) $
servant-client/test/Servant/ClientSpec.hs+2−2
@@ -307,8 +307,8 @@ spec = do
307307 _ -> fail $ "expected InvalidContentTypeHeader, but got " <> show res
308308
309309data WrappedApi where
310− WrappedApi :: (HasServer (Canonicalize api), Server api ~ EitherT ServantErr IO a,
311− HasClient (Canonicalize api), Client api ~ (BaseUrl -> EitherT ServantError IO ())) =>
310+ WrappedApi :: (HasServer api, Server api ~ EitherT ServantErr IO a,
311+ HasClient api, Client api ~ (BaseUrl -> EitherT ServantError IO ())) =>
312312 Proxy api -> WrappedApi
313313
314314
servant-docs/CHANGELOG.md−1
@@ -5,7 +5,6 @@
55* Render endpoints in a canonical order (https://github.com/haskell-servant/servant-docs/pull/15)
66* Remove ToJSON superclass from ToSample
77* Split out Internal module
8−* `Canonicalize` API types before generating the docs for them
98* Add support for response headers
109
11100.3
servant-docs/src/Servant/Docs/Internal.hs+4−8
@@ -291,8 +291,8 @@ makeLenses ''Action
291291
292292-- | Generate the docs for a given API that implements 'HasDocs'. This is the
293293-- default way to create documentation.
294−docs :: HasDocs (Canonicalize layout) => Proxy layout -> API
295−docs p = docsFor (canonicalize p) (defEndpoint, defAction)
294+docs :: HasDocs layout => Proxy layout -> API
295+docs p = docsFor p (defEndpoint, defAction)
296296
297297-- | Closed type family, check if endpoint is exactly within API.
298298
@@ -336,11 +336,7 @@ extraInfo p action =
336336-- 'extraInfo'.
337337--
338338-- If you only want to add an introduction, use 'docsWithIntros'.
339−docsWith :: HasDocs (Canonicalize layout)
340− => [DocIntro]
341− -> ExtraInfo layout
342− -> Proxy layout
343− -> API
339+docsWith :: HasDocs layout => [DocIntro] -> ExtraInfo layout -> Proxy layout -> API
344340docsWith intros (ExtraInfo endpoints) p =
345341 docs p & apiIntros <>~ intros
346342 & apiEndpoints %~ HM.unionWith combineAction endpoints
@@ -348,7 +344,7 @@ docsWith intros (ExtraInfo endpoints) p =
348344
349345-- | Generate the docs for a given API that implements 'HasDocs' with with any
350346-- number of introduction(s)
351−docsWithIntros :: HasDocs (Canonicalize layout) => [DocIntro] -> Proxy layout -> API
347+docsWithIntros :: HasDocs layout => [DocIntro] -> Proxy layout -> API
352348docsWithIntros intros = docsWith intros mempty
353349
354350-- | The class that abstracts away the impact of API combinators
servant-jquery/src/Servant/JQuery.hs+3−4
@@ -26,8 +26,8 @@ import Data.Proxy
2626import Servant.API
2727import Servant.JQuery.Internal
2828
29−jquery :: HasJQ (Canonicalize layout) => Proxy layout -> JQ layout
30−jquery p = jqueryFor (canonicalize p) defReq
29+jquery :: HasJQ layout => Proxy layout -> JQ layout
30+jquery p = jqueryFor p defReq
3131
3232-- js codegen
3333generateJS :: AjaxReq -> String
@@ -112,6 +112,5 @@ instance GenerateCode rest => GenerateCode (AjaxReq :<|> rest) where
112112-- | Directly generate all the javascript functions for your API
113113-- from a 'Proxy' for your API type. You can then write it to
114114-- a file or integrate it in a page, for example.
115−jsForAPI :: (HasJQ (Canonicalize api), GenerateCode (JQ api))
116− => Proxy api -> String
115+jsForAPI :: (HasJQ api, GenerateCode (JQ api)) => Proxy api -> String
117116jsForAPI p = jsFor (jquery p)
servant-jquery/src/Servant/JQuery/Internal.hs+18−20
@@ -194,14 +194,12 @@ type family Elem (a :: *) (ls::[*]) :: Constraint where
194194 Elem a (b ': list) = Elem a list
195195
196196class HasJQ (layout :: *) where
197− type JQ' layout :: *
198− jqueryFor :: Proxy layout -> AjaxReq -> JQ' layout
199−
200−type JQ layout = JQ' (Canonicalize layout)
197+ type JQ layout :: *
198+ jqueryFor :: Proxy layout -> AjaxReq -> JQ layout
201199
202200instance (HasJQ a, HasJQ b)
203201 => HasJQ (a :<|> b) where
204− type JQ' (a :<|> b) = JQ' a :<|> JQ' b
202+ type JQ (a :<|> b) = JQ a :<|> JQ b
205203
206204 jqueryFor Proxy req =
207205 jqueryFor (Proxy :: Proxy a) req
@@ -209,7 +207,7 @@ instance (HasJQ a, HasJQ b)
209207
210208instance (KnownSymbol sym, HasJQ sublayout)
211209 => HasJQ (Capture sym a :> sublayout) where
212− type JQ' (Capture sym a :> sublayout) = JQ' sublayout
210+ type JQ (Capture sym a :> sublayout) = JQ sublayout
213211
214212 jqueryFor Proxy req =
215213 jqueryFor (Proxy :: Proxy sublayout) $
@@ -218,14 +216,14 @@ instance (KnownSymbol sym, HasJQ sublayout)
218216 where str = symbolVal (Proxy :: Proxy sym)
219217
220218instance HasJQ Delete where
221− type JQ' Delete = AjaxReq
219+ type JQ Delete = AjaxReq
222220
223221 jqueryFor Proxy req =
224222 req & funcName %~ ("delete" <>)
225223 & reqMethod .~ "DELETE"
226224
227225instance Elem JSON list => HasJQ (Get list a) where
228− type JQ' (Get list a) = AjaxReq
226+ type JQ (Get list a) = AjaxReq
229227
230228 jqueryFor Proxy req =
231229 req & funcName %~ ("get" <>)
@@ -233,7 +231,7 @@ instance Elem JSON list => HasJQ (Get list a) where
233231
234232instance (KnownSymbol sym, HasJQ sublayout)
235233 => HasJQ (Header sym a :> sublayout) where
236− type JQ' (Header sym a :> sublayout) = JQ' sublayout
234+ type JQ (Header sym a :> sublayout) = JQ sublayout
237235
238236 jqueryFor Proxy req =
239237 jqueryFor subP (req & reqHeaders <>~ [HeaderArg hname])
@@ -242,14 +240,14 @@ instance (KnownSymbol sym, HasJQ sublayout)
242240 subP = Proxy :: Proxy sublayout
243241
244242instance Elem JSON list => HasJQ (Post list a) where
245− type JQ' (Post list a) = AjaxReq
243+ type JQ (Post list a) = AjaxReq
246244
247245 jqueryFor Proxy req =
248246 req & funcName %~ ("post" <>)
249247 & reqMethod .~ "POST"
250248
251249instance Elem JSON list => HasJQ (Put list a) where
252− type JQ' (Put list a) = AjaxReq
250+ type JQ (Put list a) = AjaxReq
253251
254252 jqueryFor Proxy req =
255253 req & funcName %~ ("put" <>)
@@ -257,7 +255,7 @@ instance Elem JSON list => HasJQ (Put list a) where
257255
258256instance (KnownSymbol sym, HasJQ sublayout)
259257 => HasJQ (QueryParam sym a :> sublayout) where
260− type JQ' (QueryParam sym a :> sublayout) = JQ' sublayout
258+ type JQ (QueryParam sym a :> sublayout) = JQ sublayout
261259
262260 jqueryFor Proxy req =
263261 jqueryFor (Proxy :: Proxy sublayout) $
@@ -267,7 +265,7 @@ instance (KnownSymbol sym, HasJQ sublayout)
267265
268266instance (KnownSymbol sym, HasJQ sublayout)
269267 => HasJQ (QueryParams sym a :> sublayout) where
270− type JQ' (QueryParams sym a :> sublayout) = JQ' sublayout
268+ type JQ (QueryParams sym a :> sublayout) = JQ sublayout
271269
272270 jqueryFor Proxy req =
273271 jqueryFor (Proxy :: Proxy sublayout) $
@@ -277,7 +275,7 @@ instance (KnownSymbol sym, HasJQ sublayout)
277275
278276instance (KnownSymbol sym, HasJQ sublayout)
279277 => HasJQ (QueryFlag sym :> sublayout) where
280− type JQ' (QueryFlag sym :> sublayout) = JQ' sublayout
278+ type JQ (QueryFlag sym :> sublayout) = JQ sublayout
281279
282280 jqueryFor Proxy req =
283281 jqueryFor (Proxy :: Proxy sublayout) $
@@ -287,7 +285,7 @@ instance (KnownSymbol sym, HasJQ sublayout)
287285
288286instance (KnownSymbol sym, HasJQ sublayout)
289287 => HasJQ (MatrixParam sym a :> sublayout) where
290− type JQ' (MatrixParam sym a :> sublayout) = JQ' sublayout
288+ type JQ (MatrixParam sym a :> sublayout) = JQ sublayout
291289
292290 jqueryFor Proxy req =
293291 jqueryFor (Proxy :: Proxy sublayout) $
@@ -298,7 +296,7 @@ instance (KnownSymbol sym, HasJQ sublayout)
298296
299297instance (KnownSymbol sym, HasJQ sublayout)
300298 => HasJQ (MatrixParams sym a :> sublayout) where
301− type JQ' (MatrixParams sym a :> sublayout) = JQ' sublayout
299+ type JQ (MatrixParams sym a :> sublayout) = JQ sublayout
302300
303301 jqueryFor Proxy req =
304302 jqueryFor (Proxy :: Proxy sublayout) $
@@ -308,7 +306,7 @@ instance (KnownSymbol sym, HasJQ sublayout)
308306
309307instance (KnownSymbol sym, HasJQ sublayout)
310308 => HasJQ (MatrixFlag sym :> sublayout) where
311− type JQ' (MatrixFlag sym :> sublayout) = JQ' sublayout
309+ type JQ (MatrixFlag sym :> sublayout) = JQ sublayout
312310
313311 jqueryFor Proxy req =
314312 jqueryFor (Proxy :: Proxy sublayout) $
@@ -317,14 +315,14 @@ instance (KnownSymbol sym, HasJQ sublayout)
317315 where str = symbolVal (Proxy :: Proxy sym)
318316
319317instance HasJQ Raw where
320− type JQ' Raw = Method -> AjaxReq
318+ type JQ Raw = Method -> AjaxReq
321319
322320 jqueryFor Proxy req method =
323321 req & funcName %~ ((toLower <$> method) <>)
324322 & reqMethod .~ method
325323
326324instance (Elem JSON list, HasJQ sublayout) => HasJQ (ReqBody list a :> sublayout) where
327− type JQ' (ReqBody list a :> sublayout) = JQ' sublayout
325+ type JQ (ReqBody list a :> sublayout) = JQ sublayout
328326
329327 jqueryFor Proxy req =
330328 jqueryFor (Proxy :: Proxy sublayout) $
@@ -332,7 +330,7 @@ instance (Elem JSON list, HasJQ sublayout) => HasJQ (ReqBody list a :> sublayout
332330
333331instance (KnownSymbol path, HasJQ sublayout)
334332 => HasJQ (path :> sublayout) where
335− type JQ' (path :> sublayout) = JQ' sublayout
333+ type JQ (path :> sublayout) = JQ sublayout
336334
337335 jqueryFor Proxy req =
338336 jqueryFor (Proxy :: Proxy sublayout) $
servant-server/CHANGELOG.md−1
@@ -5,7 +5,6 @@
55* Support for `Accept`/`Content-type` headers and for the content-type aware combinators in *servant-0.3*
66* Export `toApplication` from `Servant.Server` (https://github.com/haskell-servant/servant-server/pull/29)
77* Support other Monads than just `EitherT (Int, String) IO` (https://github.com/haskell-servant/servant-server/pull/21)
8−* Canonicalize API types before generating the handler types with `Server`
98* Make methods return status code 204 if they return () (https://github.com/haskell-servant/servant-server/issues/28)
109* Add server support for response headers
1110
servant-server/src/Servant/Server.hs+2−4
@@ -15,7 +15,6 @@ module Servant.Server
1515 , -- * Handlers for all standard combinators
1616 HasServer(..)
1717 , Server
18− , ServerT
1918
2019 -- * Enter
2120 -- $enterDoc
@@ -80,7 +79,6 @@ module Servant.Server
8079
8180import Data.Proxy (Proxy)
8281import Network.Wai (Application)
83−import Servant.API (Canonicalize, canonicalize)
8482import Servant.Server.Internal
8583import Servant.Server.Internal.Enter
8684import Servant.Server.Internal.ServantErr
@@ -109,8 +107,8 @@ import Servant.Server.Internal.ServantErr
109107-- > main :: IO ()
110108-- > main = Network.Wai.Handler.Warp.run 8080 app
111109--
112−serve :: HasServer (Canonicalize layout) => Proxy layout -> Server layout -> Application
113−serve p server = toApplication (route (canonicalize p) server)
110+serve :: HasServer layout => Proxy layout -> Server layout -> Application
111+serve p server = toApplication (route p server)
114112
115113
116114-- Documentation
servant-server/src/Servant/Server/Internal.hs+38−40
@@ -38,7 +38,7 @@ import Network.Wai (Application, Request, Response,
3838 requestMethod, responseLBS,
3939 strictRequestBody)
4040import Servant.API ((:<|>) (..), (:>), Capture,
41− Canonicalize, Delete, Get, Header,
41+ Delete, Get, Header,
4242 MatrixFlag, MatrixParam, MatrixParams,
4343 Patch, Post, Put, QueryFlag,
4444 QueryParam, QueryParams, Raw,
@@ -177,13 +177,11 @@ processedPathInfo r =
177177 where pinfo = parsePathInfo r
178178
179179class HasServer layout where
180− type ServerT' layout (m :: * -> *) :: *
180+ type ServerT layout (m :: * -> *) :: *
181181
182− route :: Proxy layout -> Server' layout -> RoutingApplication
182+ route :: Proxy layout -> Server layout -> RoutingApplication
183183
184−type Server layout = Server' (Canonicalize layout)
185−type Server' layout = ServerT' layout (EitherT ServantErr IO)
186−type ServerT layout m = ServerT' (Canonicalize layout) m
184+type Server layout = ServerT layout (EitherT ServantErr IO)
187185
188186-- * Instances
189187
@@ -200,7 +198,7 @@ type ServerT layout m = ServerT' (Canonicalize layout) m
200198-- > postBook book = ...
201199instance (HasServer a, HasServer b) => HasServer (a :<|> b) where
202200
203− type ServerT' (a :<|> b) m = ServerT' a m :<|> ServerT' b m
201+ type ServerT (a :<|> b) m = ServerT a m :<|> ServerT b m
204202
205203 route Proxy (a :<|> b) request respond =
206204 route pa a request $ \mResponse ->
@@ -234,8 +232,8 @@ captured _ = fromText
234232instance (KnownSymbol capture, FromText a, HasServer sublayout)
235233 => HasServer (Capture capture a :> sublayout) where
236234
237− type ServerT' (Capture capture a :> sublayout) m =
238− a -> ServerT' sublayout m
235+ type ServerT (Capture capture a :> sublayout) m =
236+ a -> ServerT sublayout m
239237
240238 route Proxy subserver request respond = case processedPathInfo request of
241239 (first : rest)
@@ -262,7 +260,7 @@ instance (KnownSymbol capture, FromText a, HasServer sublayout)
262260-- are not met.
263261instance HasServer Delete where
264262
265− type ServerT' Delete m = m ()
263+ type ServerT Delete m = m ()
266264
267265 route Proxy action request respond
268266 | pathIsEmpty request && requestMethod request == methodDelete = do
@@ -293,7 +291,7 @@ instance
293291#endif
294292 ( AllCTRender ctypes a ) => HasServer (Get ctypes a) where
295293
296− type ServerT' (Get ctypes a) m = m a
294+ type ServerT (Get ctypes a) m = m a
297295
298296 route Proxy action request respond
299297 | pathIsEmpty request && requestMethod request == methodGet = do
@@ -317,7 +315,7 @@ instance
317315#endif
318316 HasServer (Get ctypes ()) where
319317
320− type ServerT' (Get ctypes ()) m = m ()
318+ type ServerT (Get ctypes ()) m = m ()
321319
322320 route Proxy action request respond
323321 | pathIsEmpty request && requestMethod request == methodGet = do
@@ -337,7 +335,7 @@ instance
337335 ( GetHeaders (Headers h v), AllCTRender ctypes v
338336 ) => HasServer (Get ctypes (Headers h v)) where
339337
340− type ServerT' (Get ctypes (Headers h v)) m = m (Headers h v)
338+ type ServerT (Get ctypes (Headers h v)) m = m (Headers h v)
341339
342340 route Proxy action request respond
343341 | pathIsEmpty request && requestMethod request == methodGet = do
@@ -378,8 +376,8 @@ instance
378376instance (KnownSymbol sym, FromText a, HasServer sublayout)
379377 => HasServer (Header sym a :> sublayout) where
380378
381− type ServerT' (Header sym a :> sublayout) m =
382− Maybe a -> ServerT' sublayout m
379+ type ServerT (Header sym a :> sublayout) m =
380+ Maybe a -> ServerT sublayout m
383381
384382 route Proxy subserver request respond = do
385383 let mheader = fromText . decodeUtf8 =<< lookup str (requestHeaders request)
@@ -407,7 +405,7 @@ instance
407405 ( AllCTRender ctypes a
408406 ) => HasServer (Post ctypes a) where
409407
410− type ServerT' (Post ctypes a) m = m a
408+ type ServerT (Post ctypes a) m = m a
411409
412410 route Proxy action request respond
413411 | pathIsEmpty request && requestMethod request == methodPost = do
@@ -430,7 +428,7 @@ instance
430428#endif
431429 HasServer (Post ctypes ()) where
432430
433− type ServerT' (Post ctypes ()) m = m ()
431+ type ServerT (Post ctypes ()) m = m ()
434432
435433 route Proxy action request respond
436434 | pathIsEmpty request && requestMethod request == methodPost = do
@@ -450,7 +448,7 @@ instance
450448 ( GetHeaders (Headers h v), AllCTRender ctypes v
451449 ) => HasServer (Post ctypes (Headers h v)) where
452450
453− type ServerT' (Post ctypes (Headers h v)) m = m (Headers h v)
451+ type ServerT (Post ctypes (Headers h v)) m = m (Headers h v)
454452
455453 route Proxy action request respond
456454 | pathIsEmpty request && requestMethod request == methodPost = do
@@ -487,7 +485,7 @@ instance
487485#endif
488486 ( AllCTRender ctypes a) => HasServer (Put ctypes a) where
489487
490− type ServerT' (Put ctypes a) m = m a
488+ type ServerT (Put ctypes a) m = m a
491489
492490 route Proxy action request respond
493491 | pathIsEmpty request && requestMethod request == methodPut = do
@@ -510,7 +508,7 @@ instance
510508#endif
511509 HasServer (Put ctypes ()) where
512510
513− type ServerT' (Put ctypes ()) m = m ()
511+ type ServerT (Put ctypes ()) m = m ()
514512
515513 route Proxy action request respond
516514 | pathIsEmpty request && requestMethod request == methodPut = do
@@ -530,7 +528,7 @@ instance
530528 ( GetHeaders (Headers h v), AllCTRender ctypes v
531529 ) => HasServer (Put ctypes (Headers h v)) where
532530
533− type ServerT' (Put ctypes (Headers h v)) m = m (Headers h v)
531+ type ServerT (Put ctypes (Headers h v)) m = m (Headers h v)
534532
535533 route Proxy action request respond
536534 | pathIsEmpty request && requestMethod request == methodPut = do
@@ -565,7 +563,7 @@ instance
565563#endif
566564 ( AllCTRender ctypes a) => HasServer (Patch ctypes a) where
567565
568− type ServerT' (Patch ctypes a) m = m a
566+ type ServerT (Patch ctypes a) m = m a
569567
570568 route Proxy action request respond
571569 | pathIsEmpty request && requestMethod request == methodPatch = do
@@ -588,7 +586,7 @@ instance
588586#endif
589587 HasServer (Patch ctypes ()) where
590588
591− type ServerT' (Patch ctypes ()) m = m ()
589+ type ServerT (Patch ctypes ()) m = m ()
592590
593591 route Proxy action request respond
594592 | pathIsEmpty request && requestMethod request == methodPatch = do
@@ -608,7 +606,7 @@ instance
608606 ( GetHeaders (Headers h v), AllCTRender ctypes v
609607 ) => HasServer (Patch ctypes (Headers h v)) where
610608
611− type ServerT' (Patch ctypes (Headers h v)) m = m (Headers h v)
609+ type ServerT (Patch ctypes (Headers h v)) m = m (Headers h v)
612610
613611 route Proxy action request respond
614612 | pathIsEmpty request && requestMethod request == methodPatch = do
@@ -650,8 +648,8 @@ instance
650648instance (KnownSymbol sym, FromText a, HasServer sublayout)
651649 => HasServer (QueryParam sym a :> sublayout) where
652650
653− type ServerT' (QueryParam sym a :> sublayout) m =
654− Maybe a -> ServerT' sublayout m
651+ type ServerT (QueryParam sym a :> sublayout) m =
652+ Maybe a -> ServerT sublayout m
655653
656654 route Proxy subserver request respond = do
657655 let querytext = parseQueryText $ rawQueryString request
@@ -688,8 +686,8 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
688686instance (KnownSymbol sym, FromText a, HasServer sublayout)
689687 => HasServer (QueryParams sym a :> sublayout) where
690688
691− type ServerT' (QueryParams sym a :> sublayout) m =
692− [a] -> ServerT' sublayout m
689+ type ServerT (QueryParams sym a :> sublayout) m =
690+ [a] -> ServerT sublayout m
693691
694692 route Proxy subserver request respond = do
695693 let querytext = parseQueryText $ rawQueryString request
@@ -721,8 +719,8 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
721719instance (KnownSymbol sym, HasServer sublayout)
722720 => HasServer (QueryFlag sym :> sublayout) where
723721
724− type ServerT' (QueryFlag sym :> sublayout) m =
725− Bool -> ServerT' sublayout m
722+ type ServerT (QueryFlag sym :> sublayout) m =
723+ Bool -> ServerT sublayout m
726724
727725 route Proxy subserver request respond = do
728726 let querytext = parseQueryText $ rawQueryString request
@@ -764,8 +762,8 @@ parseMatrixText = parseQueryText
764762instance (KnownSymbol sym, FromText a, HasServer sublayout)
765763 => HasServer (MatrixParam sym a :> sublayout) where
766764
767− type ServerT' (MatrixParam sym a :> sublayout) m =
768− Maybe a -> ServerT' sublayout m
765+ type ServerT (MatrixParam sym a :> sublayout) m =
766+ Maybe a -> ServerT sublayout m
769767
770768 route Proxy subserver request respond = case parsePathInfo request of
771769 (first : _)
@@ -802,8 +800,8 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
802800instance (KnownSymbol sym, FromText a, HasServer sublayout)
803801 => HasServer (MatrixParams sym a :> sublayout) where
804802
805− type ServerT' (MatrixParams sym a :> sublayout) m =
806− [a] -> ServerT' sublayout m
803+ type ServerT (MatrixParams sym a :> sublayout) m =
804+ [a] -> ServerT sublayout m
807805
808806 route Proxy subserver request respond = case parsePathInfo request of
809807 (first : _)
@@ -836,8 +834,8 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
836834instance (KnownSymbol sym, HasServer sublayout)
837835 => HasServer (MatrixFlag sym :> sublayout) where
838836
839− type ServerT' (MatrixFlag sym :> sublayout) m =
840− Bool -> ServerT' sublayout m
837+ type ServerT (MatrixFlag sym :> sublayout) m =
838+ Bool -> ServerT sublayout m
841839
842840 route Proxy subserver request respond = case parsePathInfo request of
843841 (first : _)
@@ -865,7 +863,7 @@ instance (KnownSymbol sym, HasServer sublayout)
865863-- > server = serveDirectory "/var/www/images"
866864instance HasServer Raw where
867865
868− type ServerT' Raw m = Application
866+ type ServerT Raw m = Application
869867
870868 route Proxy rawApplication request respond =
871869 rawApplication request (respond . succeedWith)
@@ -893,8 +891,8 @@ instance HasServer Raw where
893891instance ( AllCTUnrender list a, HasServer sublayout
894892 ) => HasServer (ReqBody list a :> sublayout) where
895893
896− type ServerT' (ReqBody list a :> sublayout) m =
897− a -> ServerT' sublayout m
894+ type ServerT (ReqBody list a :> sublayout) m =
895+ a -> ServerT sublayout m
898896
899897 route Proxy subserver request respond = do
900898 -- See HTTP RFC 2616, section 7.2.1
@@ -914,7 +912,7 @@ instance ( AllCTUnrender list a, HasServer sublayout
914912-- pass the rest of the request path to @sublayout@.
915913instance (KnownSymbol path, HasServer sublayout) => HasServer (path :> sublayout) where
916914
917− type ServerT' (path :> sublayout) m = ServerT' sublayout m
915+ type ServerT (path :> sublayout) m = ServerT sublayout m
918916
919917 route Proxy subserver request respond = case processedPathInfo request of
920918 (first : rest)
servant/CHANGELOG.md−1
@@ -1,6 +1,5 @@
110.3
22---
3−* Add a `Canonicalize` type family that distributes all `:>`s inside `:<|>`s to get to the canonical type of an API -- which is then used in all other packages to avoid weird handler types in *servant-server*.
43* Multiple content-type/accept support for all the relevant combinators
54* Provide *JSON*, *PlainText*, *OctetStream* and *FormUrlEncoded* content types out of the box
65* Type-safe link generation to API endpoints
servant/src/Servant/API.hs−34
@@ -49,10 +49,6 @@ module Servant.API (
4949 module Servant.Common.Text,
5050 -- | Classes and instances for types that can be converted to and from @Text@
5151
52− -- * Canonicalizing (flattening) API types
53− Canonicalize,
54− canonicalize,
55−
5652 -- * Utilities
5753 module Servant.Utils.Links,
5854 -- | Type-safe internal URIs
@@ -88,33 +84,3 @@ import Servant.Common.Text (FromText (..), ToText (..))
8884import Servant.Utils.Links (HasLink (..), IsElem, IsElem',
8985 URI (..), safeLink)
9086
91−-- | Turn an API type into its canonical form.
92−--
93−-- The canonical form of an API type is basically the all-flattened form
94−-- of the original type. More formally, it takes a type as input and hands you
95−-- back an /equivalent/ type formed of toplevel `:<|>`-separated chains of `:>`s,
96−-- i.e with all `:>`s distributed inside the `:<|>`s.
97−--
98−-- It basically turns:
99−--
100−-- > "hello" :> (Get Hello :<|> ReqBody Hello :> Put Hello)
101−--
102−-- into
103−--
104−-- > ("hello" :> Get Hello) :<|> ("hello" :> ReqBody Hello :> Put Hello)
105−--
106−-- i.e distributing all ':>'-separated bits into the subsequent ':<|>'s.
107−type family Canonicalize api :: * where
108− -- requires UndecidableInstances
109− Canonicalize (a :> (b :<|> c)) = a :> Canonicalize b :<|> a :> Canonicalize c
110− Canonicalize ((a :<|> b) :> c) = a :> Canonicalize c :<|> b :> Canonicalize c
111− Canonicalize (a :> b) = Redex b (Canonicalize b) a
112− Canonicalize (a :<|> b) = Canonicalize a :<|> Canonicalize b
113− Canonicalize a = a
114−
115−type family Redex a b c :: * where
116− Redex a a first = Canonicalize first :> a
117− Redex a b first = Canonicalize (first :> b)
118−
119−canonicalize :: Proxy layout -> Proxy (Canonicalize layout)
120−canonicalize Proxy = Proxy