git.iko.soy/typeable/servant
on master help sign in
Rename type variables 'layout' and 'sublayout' to 'api'
commit5effdfdbbbe738908d41272705949bc7244a9c0b authorSönke Hahn <soenkehahn@gmail.com> dateThu 2 Jun 2016, 15:49 (10 years ago) parent023368c
8 files changed+205−205
servant-client/src/Servant/Client.hs+42−42 servant-docs/src/Servant/Docs/Internal.hs+53−53 servant-docs/src/Servant/Docs/Internal/Pretty.hs+2−2 servant-foreign/src/Servant/Foreign/Internal.hs+50−50 servant-js/src/Servant/JS.hs+1−1 servant-js/test/Servant/JSSpec/CustomHeaders.hs+12−12 servant-server/src/Servant/Server.hs+6−6 servant-server/src/Servant/Server/Internal.hs+39−39
servant-client/src/Servant/Client.hs+42−42
@@ -57,15 +57,15 @@ import Servant.Common.Req
5757-- > getAllBooks :: Manager -> BaseUrl -> ClientM [Book]
5858-- > postNewBook :: Book -> Manager -> BaseUrl -> ClientM Book
5959-- > (getAllBooks :<|> postNewBook) = client myApi
60−client :: HasClient layout => Proxy layout -> Client layout
60+client :: HasClient api => Proxy api -> Client api
6161client p = clientWithRoute p defReq
6262
6363-- | This class lets us define how each API combinator
6464-- influences the creation of an HTTP request. It's mostly
6565-- an internal class, you can just use 'client'.
66−class HasClient layout where
67− type Client layout :: *
68− clientWithRoute :: Proxy layout -> Req -> Client layout
66+class HasClient api where
67+ type Client api :: *
68+ clientWithRoute :: Proxy api -> Req -> Client api
6969
7070
7171-- | A client querying function for @a ':<|>' b@ will actually hand you
@@ -106,14 +106,14 @@ instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
106106-- > getBook :: Text -> Manager -> BaseUrl -> ClientM Book
107107-- > getBook = client myApi
108108-- > -- then you can just use "getBook" to query that endpoint
109−instance (KnownSymbol capture, ToHttpApiData a, HasClient sublayout)
110− => HasClient (Capture capture a :> sublayout) where
109+instance (KnownSymbol capture, ToHttpApiData a, HasClient api)
110+ => HasClient (Capture capture a :> api) where
111111
112− type Client (Capture capture a :> sublayout) =
113− a -> Client sublayout
112+ type Client (Capture capture a :> api) =
113+ a -> Client api
114114
115115 clientWithRoute Proxy req val =
116− clientWithRoute (Proxy :: Proxy sublayout)
116+ clientWithRoute (Proxy :: Proxy api)
117117 (appendToPath p req)
118118
119119 where p = unpack (toUrlPiece val)
@@ -186,14 +186,14 @@ instance OVERLAPPING_
186186-- > viewReferer = client myApi
187187-- > -- then you can just use "viewRefer" to query that endpoint
188188-- > -- specifying Nothing or e.g Just "http://haskell.org/" as arguments
189−instance (KnownSymbol sym, ToHttpApiData a, HasClient sublayout)
190− => HasClient (Header sym a :> sublayout) where
189+instance (KnownSymbol sym, ToHttpApiData a, HasClient api)
190+ => HasClient (Header sym a :> api) where
191191
192− type Client (Header sym a :> sublayout) =
193− Maybe a -> Client sublayout
192+ type Client (Header sym a :> api) =
193+ Maybe a -> Client api
194194
195195 clientWithRoute Proxy req mval =
196− clientWithRoute (Proxy :: Proxy sublayout)
196+ clientWithRoute (Proxy :: Proxy api)
197197 (maybe req
198198 (\value -> Servant.Common.Req.addHeader hname value req)
199199 mval
@@ -203,14 +203,14 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient sublayout)
203203
204204-- | Using a 'HttpVersion' combinator in your API doesn't affect the client
205205-- functions.
206−instance HasClient sublayout
207− => HasClient (HttpVersion :> sublayout) where
206+instance HasClient api
207+ => HasClient (HttpVersion :> api) where
208208
209− type Client (HttpVersion :> sublayout) =
210− Client sublayout
209+ type Client (HttpVersion :> api) =
210+ Client api
211211
212212 clientWithRoute Proxy =
213− clientWithRoute (Proxy :: Proxy sublayout)
213+ clientWithRoute (Proxy :: Proxy api)
214214
215215-- | If you use a 'QueryParam' in one of your endpoints in your API,
216216-- the corresponding querying function will automatically take
@@ -237,15 +237,15 @@ instance HasClient sublayout
237237-- > -- then you can just use "getBooksBy" to query that endpoint.
238238-- > -- 'getBooksBy Nothing' for all books
239239-- > -- 'getBooksBy (Just "Isaac Asimov")' to get all books by Isaac Asimov
240−instance (KnownSymbol sym, ToHttpApiData a, HasClient sublayout)
241− => HasClient (QueryParam sym a :> sublayout) where
240+instance (KnownSymbol sym, ToHttpApiData a, HasClient api)
241+ => HasClient (QueryParam sym a :> api) where
242242
243− type Client (QueryParam sym a :> sublayout) =
244− Maybe a -> Client sublayout
243+ type Client (QueryParam sym a :> api) =
244+ Maybe a -> Client api
245245
246246 -- if mparam = Nothing, we don't add it to the query string
247247 clientWithRoute Proxy req mparam =
248− clientWithRoute (Proxy :: Proxy sublayout)
248+ clientWithRoute (Proxy :: Proxy api)
249249 (maybe req
250250 (flip (appendToQueryString pname) req . Just)
251251 mparamText
@@ -282,14 +282,14 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient sublayout)
282282-- > -- 'getBooksBy []' for all books
283283-- > -- 'getBooksBy ["Isaac Asimov", "Robert A. Heinlein"]'
284284-- > -- to get all books by Asimov and Heinlein
285−instance (KnownSymbol sym, ToHttpApiData a, HasClient sublayout)
286− => HasClient (QueryParams sym a :> sublayout) where
285+instance (KnownSymbol sym, ToHttpApiData a, HasClient api)
286+ => HasClient (QueryParams sym a :> api) where
287287
288− type Client (QueryParams sym a :> sublayout) =
289− [a] -> Client sublayout
288+ type Client (QueryParams sym a :> api) =
289+ [a] -> Client api
290290
291291 clientWithRoute Proxy req paramlist =
292− clientWithRoute (Proxy :: Proxy sublayout)
292+ clientWithRoute (Proxy :: Proxy api)
293293 (foldl' (\ req' -> maybe req' (flip (appendToQueryString pname) req' . Just))
294294 req
295295 paramlist'
@@ -320,14 +320,14 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient sublayout)
320320-- > -- then you can just use "getBooks" to query that endpoint.
321321-- > -- 'getBooksBy False' for all books
322322-- > -- 'getBooksBy True' to only get _already published_ books
323−instance (KnownSymbol sym, HasClient sublayout)
324− => HasClient (QueryFlag sym :> sublayout) where
323+instance (KnownSymbol sym, HasClient api)
324+ => HasClient (QueryFlag sym :> api) where
325325
326− type Client (QueryFlag sym :> sublayout) =
327− Bool -> Client sublayout
326+ type Client (QueryFlag sym :> api) =
327+ Bool -> Client api
328328
329329 clientWithRoute Proxy req flag =
330− clientWithRoute (Proxy :: Proxy sublayout)
330+ clientWithRoute (Proxy :: Proxy api)
331331 (if flag
332332 then appendToQueryString paramname Nothing req
333333 else req
@@ -364,14 +364,14 @@ instance HasClient Raw where
364364-- > addBook :: Book -> Manager -> BaseUrl -> ClientM Book
365365-- > addBook = client myApi
366366-- > -- then you can just use "addBook" to query that endpoint
367−instance (MimeRender ct a, HasClient sublayout)
368− => HasClient (ReqBody (ct ': cts) a :> sublayout) where
367+instance (MimeRender ct a, HasClient api)
368+ => HasClient (ReqBody (ct ': cts) a :> api) where
369369
370− type Client (ReqBody (ct ': cts) a :> sublayout) =
371− a -> Client sublayout
370+ type Client (ReqBody (ct ': cts) a :> api) =
371+ a -> Client api
372372
373373 clientWithRoute Proxy req body =
374− clientWithRoute (Proxy :: Proxy sublayout)
374+ clientWithRoute (Proxy :: Proxy api)
375375 (let ctProxy = Proxy :: Proxy ct
376376 in setRQBody (mimeRender ctProxy body)
377377 (contentType ctProxy)
@@ -379,11 +379,11 @@ instance (MimeRender ct a, HasClient sublayout)
379379 )
380380
381381-- | Make the querying function append @path@ to the request path.
382−instance (KnownSymbol path, HasClient sublayout) => HasClient (path :> sublayout) where
383− type Client (path :> sublayout) = Client sublayout
382+instance (KnownSymbol path, HasClient api) => HasClient (path :> api) where
383+ type Client (path :> api) = Client api
384384
385385 clientWithRoute Proxy req =
386− clientWithRoute (Proxy :: Proxy sublayout)
386+ clientWithRoute (Proxy :: Proxy api)
387387 (appendToPath p req)
388388
389389 where p = symbolVal (Proxy :: Proxy path)
servant-docs/src/Servant/Docs/Internal.hs+53−53
@@ -163,7 +163,7 @@ data DocNote = DocNote
163163--
164164-- These are intended to be built using extraInfo.
165165-- Multiple ExtraInfo may be combined with the monoid instance.
166−newtype ExtraInfo layout = ExtraInfo (HashMap Endpoint Action)
166+newtype ExtraInfo api = ExtraInfo (HashMap Endpoint Action)
167167instance Monoid (ExtraInfo a) where
168168 mempty = ExtraInfo mempty
169169 ExtraInfo a `mappend` ExtraInfo b =
@@ -300,11 +300,11 @@ makeLenses ''Action
300300-- default way to create documentation.
301301--
302302-- prop> docs == docsWithOptions defaultDocOptions
303−docs :: HasDocs layout => Proxy layout -> API
303+docs :: HasDocs api => Proxy api -> API
304304docs p = docsWithOptions p defaultDocOptions
305305
306306-- | Generate the docs for a given API that implements 'HasDocs'.
307−docsWithOptions :: HasDocs layout => Proxy layout -> DocOptions -> API
307+docsWithOptions :: HasDocs api => Proxy api -> DocOptions -> API
308308docsWithOptions p = docsFor p (defEndpoint, defAction)
309309
310310-- | Closed type family, check if endpoint is exactly within API.
@@ -316,7 +316,7 @@ type family IsIn (endpoint :: *) (api :: *) :: Constraint where
316316 IsIn (e :> sa) (e :> sb) = IsIn sa sb
317317 IsIn e e = ()
318318
319−-- | Create an 'ExtraInfo' that is garunteed to be within the given API layout.
319+-- | Create an 'ExtraInfo' that is guaranteed to be within the given API layout.
320320--
321321-- The safety here is to ensure that you only add custom documentation to an
322322-- endpoint that actually exists within your API.
@@ -329,8 +329,8 @@ type family IsIn (endpoint :: *) (api :: *) :: Constraint where
329329-- > , DocNote "Second secton" ["And some more"]
330330-- > ]
331331
332−extraInfo :: (IsIn endpoint layout, HasLink endpoint, HasDocs endpoint)
333− => Proxy endpoint -> Action -> ExtraInfo layout
332+extraInfo :: (IsIn endpoint api, HasLink endpoint, HasDocs endpoint)
333+ => Proxy endpoint -> Action -> ExtraInfo api
334334extraInfo p action =
335335 let api = docsFor p (defEndpoint, defAction) defaultDocOptions
336336 -- Assume one endpoint, HasLink constraint means that we should only ever
@@ -349,7 +349,7 @@ extraInfo p action =
349349-- 'extraInfo'.
350350--
351351-- If you only want to add an introduction, use 'docsWithIntros'.
352−docsWith :: HasDocs layout => DocOptions -> [DocIntro] -> ExtraInfo layout -> Proxy layout -> API
352+docsWith :: HasDocs api => DocOptions -> [DocIntro] -> ExtraInfo api -> Proxy api -> API
353353docsWith opts intros (ExtraInfo endpoints) p =
354354 docsWithOptions p opts
355355 & apiIntros <>~ intros
@@ -358,13 +358,13 @@ docsWith opts intros (ExtraInfo endpoints) p =
358358
359359-- | Generate the docs for a given API that implements 'HasDocs' with with any
360360-- number of introduction(s)
361−docsWithIntros :: HasDocs layout => [DocIntro] -> Proxy layout -> API
361+docsWithIntros :: HasDocs api => [DocIntro] -> Proxy api -> API
362362docsWithIntros intros = docsWith defaultDocOptions intros mempty
363363
364364-- | The class that abstracts away the impact of API combinators
365365-- on documentation generation.
366−class HasDocs layout where
367− docsFor :: Proxy layout -> (Endpoint, Action) -> DocOptions -> API
366+class HasDocs api where
367+ docsFor :: Proxy api -> (Endpoint, Action) -> DocOptions -> API
368368
369369-- | The class that lets us display a sample input or output in the supported
370370-- content-types when generating documentation for endpoints that either:
@@ -675,26 +675,26 @@ markdown api = unlines $
675675-- | The generated docs for @a ':<|>' b@ just appends the docs
676676-- for @a@ with the docs for @b@.
677677instance OVERLAPPABLE_
678− (HasDocs layout1, HasDocs layout2)
679− => HasDocs (layout1 :<|> layout2) where
678+ (HasDocs a, HasDocs b)
679+ => HasDocs (a :<|> b) where
680680
681681 docsFor Proxy (ep, action) = docsFor p1 (ep, action) <> docsFor p2 (ep, action)
682682
683− where p1 :: Proxy layout1
683+ where p1 :: Proxy a
684684 p1 = Proxy
685685
686− p2 :: Proxy layout2
686+ p2 :: Proxy b
687687 p2 = Proxy
688688
689689-- | @"books" :> 'Capture' "isbn" Text@ will appear as
690690-- @/books/:isbn@ in the docs.
691−instance (KnownSymbol sym, ToCapture (Capture sym a), HasDocs sublayout)
692− => HasDocs (Capture sym a :> sublayout) where
691+instance (KnownSymbol sym, ToCapture (Capture sym a), HasDocs api)
692+ => HasDocs (Capture sym a :> api) where
693693
694694 docsFor Proxy (endpoint, action) =
695− docsFor sublayoutP (endpoint', action')
695+ docsFor subApiP (endpoint', action')
696696
697− where sublayoutP = Proxy :: Proxy sublayout
697+ where subApiP = Proxy :: Proxy api
698698 captureP = Proxy :: Proxy (Capture sym a)
699699
700700 action' = over captures (|> toCapture captureP) action
@@ -736,43 +736,43 @@ instance OVERLAPPING_
736736 status = fromInteger $ natVal (Proxy :: Proxy status)
737737 p = Proxy :: Proxy a
738738
739−instance (KnownSymbol sym, HasDocs sublayout)
740− => HasDocs (Header sym a :> sublayout) where
739+instance (KnownSymbol sym, HasDocs api)
740+ => HasDocs (Header sym a :> api) where
741741 docsFor Proxy (endpoint, action) =
742− docsFor sublayoutP (endpoint, action')
742+ docsFor subApiP (endpoint, action')
743743
744− where sublayoutP = Proxy :: Proxy sublayout
744+ where subApiP = Proxy :: Proxy api
745745 action' = over headers (|> headername) action
746746 headername = T.pack $ symbolVal (Proxy :: Proxy sym)
747747
748−instance (KnownSymbol sym, ToParam (QueryParam sym a), HasDocs sublayout)
749− => HasDocs (QueryParam sym a :> sublayout) where
748+instance (KnownSymbol sym, ToParam (QueryParam sym a), HasDocs api)
749+ => HasDocs (QueryParam sym a :> api) where
750750
751751 docsFor Proxy (endpoint, action) =
752− docsFor sublayoutP (endpoint, action')
752+ docsFor subApiP (endpoint, action')
753753
754− where sublayoutP = Proxy :: Proxy sublayout
754+ where subApiP = Proxy :: Proxy api
755755 paramP = Proxy :: Proxy (QueryParam sym a)
756756 action' = over params (|> toParam paramP) action
757757
758−instance (KnownSymbol sym, ToParam (QueryParams sym a), HasDocs sublayout)
759− => HasDocs (QueryParams sym a :> sublayout) where
758+instance (KnownSymbol sym, ToParam (QueryParams sym a), HasDocs api)
759+ => HasDocs (QueryParams sym a :> api) where
760760
761761 docsFor Proxy (endpoint, action) =
762− docsFor sublayoutP (endpoint, action')
762+ docsFor subApiP (endpoint, action')
763763
764− where sublayoutP = Proxy :: Proxy sublayout
764+ where subApiP = Proxy :: Proxy api
765765 paramP = Proxy :: Proxy (QueryParams sym a)
766766 action' = over params (|> toParam paramP) action
767767
768768
769−instance (KnownSymbol sym, ToParam (QueryFlag sym), HasDocs sublayout)
770− => HasDocs (QueryFlag sym :> sublayout) where
769+instance (KnownSymbol sym, ToParam (QueryFlag sym), HasDocs api)
770+ => HasDocs (QueryFlag sym :> api) where
771771
772772 docsFor Proxy (endpoint, action) =
773− docsFor sublayoutP (endpoint, action')
773+ docsFor subApiP (endpoint, action')
774774
775− where sublayoutP = Proxy :: Proxy sublayout
775+ where subApiP = Proxy :: Proxy api
776776 paramP = Proxy :: Proxy (QueryFlag sym)
777777 action' = over params (|> toParam paramP) action
778778
@@ -785,49 +785,49 @@ instance HasDocs Raw where
785785-- example data. However, there's no reason to believe that the instances of
786786-- 'AllMimeUnrender' and 'AllMimeRender' actually agree (or to suppose that
787787-- both are even defined) for any particular type.
788−instance (ToSample a, AllMimeRender (ct ': cts) a, HasDocs sublayout)
789− => HasDocs (ReqBody (ct ': cts) a :> sublayout) where
788+instance (ToSample a, AllMimeRender (ct ': cts) a, HasDocs api)
789+ => HasDocs (ReqBody (ct ': cts) a :> api) where
790790
791791 docsFor Proxy (endpoint, action) =
792− docsFor sublayoutP (endpoint, action')
792+ docsFor subApiP (endpoint, action')
793793
794− where sublayoutP = Proxy :: Proxy sublayout
794+ where subApiP = Proxy :: Proxy api
795795 action' = action & rqbody .~ sampleByteString t p
796796 & rqtypes .~ allMime t
797797 t = Proxy :: Proxy (ct ': cts)
798798 p = Proxy :: Proxy a
799799
800−instance (KnownSymbol path, HasDocs sublayout) => HasDocs (path :> sublayout) where
800+instance (KnownSymbol path, HasDocs api) => HasDocs (path :> api) where
801801
802802 docsFor Proxy (endpoint, action) =
803− docsFor sublayoutP (endpoint', action)
803+ docsFor subApiP (endpoint', action)
804804
805− where sublayoutP = Proxy :: Proxy sublayout
805+ where subApiP = Proxy :: Proxy api
806806 endpoint' = endpoint & path <>~ [symbolVal pa]
807807 pa = Proxy :: Proxy path
808808
809−instance HasDocs sublayout => HasDocs (RemoteHost :> sublayout) where
809+instance HasDocs api => HasDocs (RemoteHost :> api) where
810810 docsFor Proxy ep =
811− docsFor (Proxy :: Proxy sublayout) ep
811+ docsFor (Proxy :: Proxy api) ep
812812
813−instance HasDocs sublayout => HasDocs (IsSecure :> sublayout) where
813+instance HasDocs api => HasDocs (IsSecure :> api) where
814814 docsFor Proxy ep =
815− docsFor (Proxy :: Proxy sublayout) ep
815+ docsFor (Proxy :: Proxy api) ep
816816
817−instance HasDocs sublayout => HasDocs (HttpVersion :> sublayout) where
817+instance HasDocs api => HasDocs (HttpVersion :> api) where
818818 docsFor Proxy ep =
819− docsFor (Proxy :: Proxy sublayout) ep
819+ docsFor (Proxy :: Proxy api) ep
820820
821−instance HasDocs sublayout => HasDocs (Vault :> sublayout) where
821+instance HasDocs api => HasDocs (Vault :> api) where
822822 docsFor Proxy ep =
823− docsFor (Proxy :: Proxy sublayout) ep
823+ docsFor (Proxy :: Proxy api) ep
824824
825−instance HasDocs sublayout => HasDocs (WithNamedContext name context sublayout) where
826− docsFor Proxy = docsFor (Proxy :: Proxy sublayout)
825+instance HasDocs api => HasDocs (WithNamedContext name context api) where
826+ docsFor Proxy = docsFor (Proxy :: Proxy api)
827827
828−instance (ToAuthInfo (BasicAuth realm usr), HasDocs sublayout) => HasDocs (BasicAuth realm usr :> sublayout) where
828+instance (ToAuthInfo (BasicAuth realm usr), HasDocs api) => HasDocs (BasicAuth realm usr :> api) where
829829 docsFor Proxy (endpoint, action) =
830− docsFor (Proxy :: Proxy sublayout) (endpoint, action')
830+ docsFor (Proxy :: Proxy api) (endpoint, action')
831831 where
832832 authProxy = Proxy :: Proxy (BasicAuth realm usr)
833833 action' = over authInfo (|> toAuthInfo authProxy) action
servant-docs/src/Servant/Docs/Internal/Pretty.hs+2−2
@@ -29,12 +29,12 @@ instance ToJSON a => MimeRender PrettyJSON a where
2929-- @
3030-- 'docs' ('pretty' ('Proxy' :: 'Proxy' MyAPI))
3131-- @
32−pretty :: Proxy layout -> Proxy (Pretty layout)
32+pretty :: Proxy api -> Proxy (Pretty api)
3333pretty Proxy = Proxy
3434
3535-- | Replace all JSON content types with PrettyJSON.
3636-- Kind-polymorphic so it can operate on kinds @*@ and @[*]@.
37−type family Pretty (layout :: k) :: k where
37+type family Pretty (api :: k) :: k where
3838 Pretty (x :<|> y) = Pretty x :<|> Pretty y
3939 Pretty (x :> y) = Pretty x :> Pretty y
4040 Pretty (Get cs r) = Get (Pretty cs) r
servant-foreign/src/Servant/Foreign/Internal.hs+50−50
@@ -184,9 +184,9 @@ data NoTypes
184184instance HasForeignType NoTypes () ftype where
185185 typeFor _ _ _ = ()
186186
187−class HasForeign lang ftype (layout :: *) where
188− type Foreign ftype layout :: *
189− foreignFor :: Proxy lang -> Proxy ftype -> Proxy layout -> Req ftype -> Foreign ftype layout
187+class HasForeign lang ftype (api :: *) where
188+ type Foreign ftype api :: *
189+ foreignFor :: Proxy lang -> Proxy ftype -> Proxy api -> Req ftype -> Foreign ftype api
190190
191191instance (HasForeign lang ftype a, HasForeign lang ftype b)
192192 => HasForeign lang ftype (a :<|> b) where
@@ -196,12 +196,12 @@ instance (HasForeign lang ftype a, HasForeign lang ftype b)
196196 foreignFor lang ftype (Proxy :: Proxy a) req
197197 :<|> foreignFor lang ftype (Proxy :: Proxy b) req
198198
199−instance (KnownSymbol sym, HasForeignType lang ftype t, HasForeign lang ftype sublayout)
200− => HasForeign lang ftype (Capture sym t :> sublayout) where
201− type Foreign ftype (Capture sym a :> sublayout) = Foreign ftype sublayout
199+instance (KnownSymbol sym, HasForeignType lang ftype t, HasForeign lang ftype api)
200+ => HasForeign lang ftype (Capture sym t :> api) where
201+ type Foreign ftype (Capture sym a :> api) = Foreign ftype api
202202
203203 foreignFor lang Proxy Proxy req =
204− foreignFor lang Proxy (Proxy :: Proxy sublayout) $
204+ foreignFor lang Proxy (Proxy :: Proxy api) $
205205 req & reqUrl . path <>~ [Segment (Cap arg)]
206206 & reqFuncName . _FunctionName %~ (++ ["by", str])
207207 where
@@ -224,9 +224,9 @@ instance (Elem JSON list, HasForeignType lang ftype a, ReflectMethod method)
224224 method = reflectMethod (Proxy :: Proxy method)
225225 methodLC = toLower $ decodeUtf8 method
226226
227−instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype sublayout)
228− => HasForeign lang ftype (Header sym a :> sublayout) where
229− type Foreign ftype (Header sym a :> sublayout) = Foreign ftype sublayout
227+instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype api)
228+ => HasForeign lang ftype (Header sym a :> api) where
229+ type Foreign ftype (Header sym a :> api) = Foreign ftype api
230230
231231 foreignFor lang Proxy Proxy req =
232232 foreignFor lang Proxy subP $ req & reqHeaders <>~ [HeaderArg arg]
@@ -235,14 +235,14 @@ instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype su
235235 arg = Arg
236236 { _argName = PathSegment hname
237237 , _argType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy a) }
238− subP = Proxy :: Proxy sublayout
238+ subP = Proxy :: Proxy api
239239
240−instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype sublayout)
241− => HasForeign lang ftype (QueryParam sym a :> sublayout) where
242− type Foreign ftype (QueryParam sym a :> sublayout) = Foreign ftype sublayout
240+instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype api)
241+ => HasForeign lang ftype (QueryParam sym a :> api) where
242+ type Foreign ftype (QueryParam sym a :> api) = Foreign ftype api
243243
244244 foreignFor lang Proxy Proxy req =
245− foreignFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy sublayout) $
245+ foreignFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy api) $
246246 req & reqUrl.queryStr <>~ [QueryArg arg Normal]
247247 where
248248 str = pack . symbolVal $ (Proxy :: Proxy sym)
@@ -251,11 +251,11 @@ instance (KnownSymbol sym, HasForeignType lang ftype a, HasForeign lang ftype su
251251 , _argType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy a) }
252252
253253instance
254− (KnownSymbol sym, HasForeignType lang ftype [a], HasForeign lang ftype sublayout)
255− => HasForeign lang ftype (QueryParams sym a :> sublayout) where
256− type Foreign ftype (QueryParams sym a :> sublayout) = Foreign ftype sublayout
254+ (KnownSymbol sym, HasForeignType lang ftype [a], HasForeign lang ftype api)
255+ => HasForeign lang ftype (QueryParams sym a :> api) where
256+ type Foreign ftype (QueryParams sym a :> api) = Foreign ftype api
257257 foreignFor lang Proxy Proxy req =
258− foreignFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy sublayout) $
258+ foreignFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy api) $
259259 req & reqUrl.queryStr <>~ [QueryArg arg List]
260260 where
261261 str = pack . symbolVal $ (Proxy :: Proxy sym)
@@ -264,12 +264,12 @@ instance
264264 , _argType = typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy [a]) }
265265
266266instance
267− (KnownSymbol sym, HasForeignType lang ftype Bool, HasForeign lang ftype sublayout)
268− => HasForeign lang ftype (QueryFlag sym :> sublayout) where
269− type Foreign ftype (QueryFlag sym :> sublayout) = Foreign ftype sublayout
267+ (KnownSymbol sym, HasForeignType lang ftype Bool, HasForeign lang ftype api)
268+ => HasForeign lang ftype (QueryFlag sym :> api) where
269+ type Foreign ftype (QueryFlag sym :> api) = Foreign ftype api
270270
271271 foreignFor lang ftype Proxy req =
272− foreignFor lang ftype (Proxy :: Proxy sublayout) $
272+ foreignFor lang ftype (Proxy :: Proxy api) $
273273 req & reqUrl.queryStr <>~ [QueryArg arg Flag]
274274 where
275275 str = pack . symbolVal $ (Proxy :: Proxy sym)
@@ -284,20 +284,20 @@ instance HasForeign lang ftype Raw where
284284 req & reqFuncName . _FunctionName %~ ((toLower $ decodeUtf8 method) :)
285285 & reqMethod .~ method
286286
287−instance (Elem JSON list, HasForeignType lang ftype a, HasForeign lang ftype sublayout)
288− => HasForeign lang ftype (ReqBody list a :> sublayout) where
289− type Foreign ftype (ReqBody list a :> sublayout) = Foreign ftype sublayout
287+instance (Elem JSON list, HasForeignType lang ftype a, HasForeign lang ftype api)
288+ => HasForeign lang ftype (ReqBody list a :> api) where
289+ type Foreign ftype (ReqBody list a :> api) = Foreign ftype api
290290
291291 foreignFor lang ftype Proxy req =
292− foreignFor lang ftype (Proxy :: Proxy sublayout) $
292+ foreignFor lang ftype (Proxy :: Proxy api) $
293293 req & reqBody .~ (Just $ typeFor lang ftype (Proxy :: Proxy a))
294294
295−instance (KnownSymbol path, HasForeign lang ftype sublayout)
296− => HasForeign lang ftype (path :> sublayout) where
297− type Foreign ftype (path :> sublayout) = Foreign ftype sublayout
295+instance (KnownSymbol path, HasForeign lang ftype api)
296+ => HasForeign lang ftype (path :> api) where
297+ type Foreign ftype (path :> api) = Foreign ftype api
298298
299299 foreignFor lang ftype Proxy req =
300− foreignFor lang ftype (Proxy :: Proxy sublayout) $
300+ foreignFor lang ftype (Proxy :: Proxy api) $
301301 req & reqUrl . path <>~ [Segment (Static (PathSegment str))]
302302 & reqFuncName . _FunctionName %~ (++ [str])
303303 where
@@ -305,39 +305,39 @@ instance (KnownSymbol path, HasForeign lang ftype sublayout)
305305 Data.Text.map (\c -> if c == '.' then '_' else c)
306306 . pack . symbolVal $ (Proxy :: Proxy path)
307307
308−instance HasForeign lang ftype sublayout
309− => HasForeign lang ftype (RemoteHost :> sublayout) where
310− type Foreign ftype (RemoteHost :> sublayout) = Foreign ftype sublayout
308+instance HasForeign lang ftype api
309+ => HasForeign lang ftype (RemoteHost :> api) where
310+ type Foreign ftype (RemoteHost :> api) = Foreign ftype api
311311
312312 foreignFor lang ftype Proxy req =
313− foreignFor lang ftype (Proxy :: Proxy sublayout) req
313+ foreignFor lang ftype (Proxy :: Proxy api) req
314314
315−instance HasForeign lang ftype sublayout
316− => HasForeign lang ftype (IsSecure :> sublayout) where
317− type Foreign ftype (IsSecure :> sublayout) = Foreign ftype sublayout
315+instance HasForeign lang ftype api
316+ => HasForeign lang ftype (IsSecure :> api) where
317+ type Foreign ftype (IsSecure :> api) = Foreign ftype api
318318
319319 foreignFor lang ftype Proxy req =
320− foreignFor lang ftype (Proxy :: Proxy sublayout) req
320+ foreignFor lang ftype (Proxy :: Proxy api) req
321321
322−instance HasForeign lang ftype sublayout => HasForeign lang ftype (Vault :> sublayout) where
323− type Foreign ftype (Vault :> sublayout) = Foreign ftype sublayout
322+instance HasForeign lang ftype api => HasForeign lang ftype (Vault :> api) where
323+ type Foreign ftype (Vault :> api) = Foreign ftype api
324324
325325 foreignFor lang ftype Proxy req =
326− foreignFor lang ftype (Proxy :: Proxy sublayout) req
326+ foreignFor lang ftype (Proxy :: Proxy api) req
327327
328−instance HasForeign lang ftype sublayout =>
329− HasForeign lang ftype (WithNamedContext name context sublayout) where
328+instance HasForeign lang ftype api =>
329+ HasForeign lang ftype (WithNamedContext name context api) where
330330
331− type Foreign ftype (WithNamedContext name context sublayout) = Foreign ftype sublayout
331+ type Foreign ftype (WithNamedContext name context api) = Foreign ftype api
332332
333− foreignFor lang ftype Proxy = foreignFor lang ftype (Proxy :: Proxy sublayout)
333+ foreignFor lang ftype Proxy = foreignFor lang ftype (Proxy :: Proxy api)
334334
335−instance HasForeign lang ftype sublayout
336− => HasForeign lang ftype (HttpVersion :> sublayout) where
337− type Foreign ftype (HttpVersion :> sublayout) = Foreign ftype sublayout
335+instance HasForeign lang ftype api
336+ => HasForeign lang ftype (HttpVersion :> api) where
337+ type Foreign ftype (HttpVersion :> api) = Foreign ftype api
338338
339339 foreignFor lang ftype Proxy req =
340− foreignFor lang ftype (Proxy :: Proxy sublayout) req
340+ foreignFor lang ftype (Proxy :: Proxy api) req
341341
342342-- | Utility class used by 'listFromAPI' which computes
343343-- the data needed to generate a function for each endpoint
servant-js/src/Servant/JS.hs+1−1
@@ -128,7 +128,7 @@ import Servant.Foreign (listFromAPI)
128128-- | Generate the data necessary to generate javascript code
129129-- for all the endpoints of an API, as ':<|>'-separated values
130130-- of type 'AjaxReq'.
131−javascript :: HasForeign NoTypes () layout => Proxy layout -> Foreign () layout
131+javascript :: HasForeign NoTypes () api => Proxy api -> Foreign () api
132132javascript p = foreignFor (Proxy :: Proxy NoTypes) (Proxy :: Proxy ()) p defReq
133133
134134-- | Directly generate all the javascript functions for your API
servant-js/test/Servant/JSSpec/CustomHeaders.hs+12−12
@@ -23,11 +23,11 @@ import Servant.JS.Internal
2323-- using -- Basic, Digest, whatever.
2424data Authorization (sym :: Symbol) a
2525
26−instance (KnownSymbol sym, HasForeign lang () sublayout)
27− => HasForeign lang () (Authorization sym a :> sublayout) where
28− type Foreign () (Authorization sym a :> sublayout) = Foreign () sublayout
26+instance (KnownSymbol sym, HasForeign lang () api)
27+ => HasForeign lang () (Authorization sym a :> api) where
28+ type Foreign () (Authorization sym a :> api) = Foreign () api
2929
30− foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy sublayout) $
30+ foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $
3131 req & reqHeaders <>~
3232 [ ReplaceHeaderArg (Arg "Authorization" ())
3333 $ tokenType (pack . symbolVal $ (Proxy :: Proxy sym)) ]
@@ -37,11 +37,11 @@ instance (KnownSymbol sym, HasForeign lang () sublayout)
3737-- | This is a combinator that fetches an X-MyLovelyHorse header.
3838data MyLovelyHorse a
3939
40−instance (HasForeign lang () sublayout)
41− => HasForeign lang () (MyLovelyHorse a :> sublayout) where
42− type Foreign () (MyLovelyHorse a :> sublayout) = Foreign () sublayout
40+instance (HasForeign lang () api)
41+ => HasForeign lang () (MyLovelyHorse a :> api) where
42+ type Foreign () (MyLovelyHorse a :> api) = Foreign () api
4343
44− foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy sublayout) $
44+ foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $
4545 req & reqHeaders <>~ [ ReplaceHeaderArg (Arg "X-MyLovelyHorse" ()) tpl ]
4646 where
4747 tpl = "I am good friends with {X-MyLovelyHorse}"
@@ -49,11 +49,11 @@ instance (HasForeign lang () sublayout)
4949-- | This is a combinator that fetches an X-WhatsForDinner header.
5050data WhatsForDinner a
5151
52−instance (HasForeign lang () sublayout)
53− => HasForeign lang () (WhatsForDinner a :> sublayout) where
54− type Foreign () (WhatsForDinner a :> sublayout) = Foreign () sublayout
52+instance (HasForeign lang () api)
53+ => HasForeign lang () (WhatsForDinner a :> api) where
54+ type Foreign () (WhatsForDinner a :> api) = Foreign () api
5555
56− foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy sublayout) $
56+ foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $
5757 req & reqHeaders <>~ [ ReplaceHeaderArg (Arg "X-WhatsForDinner" ()) tpl ]
5858 where
5959 tpl = "I would like {X-WhatsForDinner} with a cherry on top."
servant-server/src/Servant/Server.hs+6−6
@@ -130,11 +130,11 @@ import Servant.Utils.Enter
130130-- > main :: IO ()
131131-- > main = Network.Wai.Handler.Warp.run 8080 app
132132--
133−serve :: (HasServer layout '[]) => Proxy layout -> Server layout -> Application
133+serve :: (HasServer api '[]) => Proxy api -> Server api -> Application
134134serve p = serveWithContext p EmptyContext
135135
136−serveWithContext :: (HasServer layout context)
137− => Proxy layout -> Context context -> Server layout -> Application
136+serveWithContext :: (HasServer api context)
137+ => Proxy api -> Context context -> Server api -> Application
138138serveWithContext p context server =
139139 toApplication (runRouter (route p context (emptyDelayed (Route server))))
140140
@@ -189,12 +189,12 @@ serveWithContext p context server =
189189-- that one takes precedence. If both parts fail, the \"better\" error
190190-- code will be returned.
191191--
192−layout :: (HasServer layout '[]) => Proxy layout -> Text
192+layout :: (HasServer api '[]) => Proxy api -> Text
193193layout p = layoutWithContext p EmptyContext
194194
195195-- | Variant of 'layout' that takes an additional 'Context'.
196−layoutWithContext :: (HasServer layout context)
197− => Proxy layout -> Context context -> Text
196+layoutWithContext :: (HasServer api context)
197+ => Proxy api -> Context context -> Text
198198layoutWithContext p context =
199199 routerLayout (route p context (emptyDelayed (FailFatal err501)))
200200
servant-server/src/Servant/Server/Internal.hs+39−39
@@ -68,16 +68,16 @@ import Servant.Server.Internal.RoutingApplication
6868import Servant.Server.Internal.ServantErr
6969
7070
71−class HasServer layout context where
72− type ServerT layout (m :: * -> *) :: *
71+class HasServer api context where
72+ type ServerT api (m :: * -> *) :: *
7373
7474 route ::
75− Proxy layout
75+ Proxy api
7676 -> Context context
77− -> Delayed env (Server layout)
77+ -> Delayed env (Server api)
7878 -> Router env
7979
80−type Server layout = ServerT layout Handler
80+type Server api = ServerT api Handler
8181
8282-- * Instances
8383
@@ -118,15 +118,15 @@ instance (HasServer a context, HasServer b context) => HasServer (a :<|> b) cont
118118-- > server = getBook
119119-- > where getBook :: Text -> Handler Book
120120-- > getBook isbn = ...
121−instance (KnownSymbol capture, FromHttpApiData a, HasServer sublayout context)
122− => HasServer (Capture capture a :> sublayout) context where
121+instance (KnownSymbol capture, FromHttpApiData a, HasServer api context)
122+ => HasServer (Capture capture a :> api) context where
123123
124− type ServerT (Capture capture a :> sublayout) m =
125− a -> ServerT sublayout m
124+ type ServerT (Capture capture a :> api) m =
125+ a -> ServerT api m
126126
127127 route Proxy context d =
128128 CaptureRouter $
129− route (Proxy :: Proxy sublayout)
129+ route (Proxy :: Proxy api)
130130 context
131131 (addCapture d $ \ txt -> case parseUrlPieceMaybe txt :: Maybe a of
132132 Nothing -> delayedFail err400
@@ -236,15 +236,15 @@ instance OVERLAPPING_
236236-- > server = viewReferer
237237-- > where viewReferer :: Referer -> Handler referer
238238-- > viewReferer referer = return referer
239−instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
240− => HasServer (Header sym a :> sublayout) context where
239+instance (KnownSymbol sym, FromHttpApiData a, HasServer api context)
240+ => HasServer (Header sym a :> api) context where
241241
242− type ServerT (Header sym a :> sublayout) m =
243− Maybe a -> ServerT sublayout m
242+ type ServerT (Header sym a :> api) m =
243+ Maybe a -> ServerT api m
244244
245245 route Proxy context subserver =
246246 let mheader req = parseHeaderMaybe =<< lookup str (requestHeaders req)
247− in route (Proxy :: Proxy sublayout) context (passToServer subserver mheader)
247+ in route (Proxy :: Proxy api) context (passToServer subserver mheader)
248248 where str = fromString $ symbolVal (Proxy :: Proxy sym)
249249
250250-- | If you use @'QueryParam' "author" Text@ in one of the endpoints for your API,
@@ -268,11 +268,11 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
268268-- > where getBooksBy :: Maybe Text -> Handler [Book]
269269-- > getBooksBy Nothing = ...return all books...
270270-- > getBooksBy (Just author) = ...return books by the given author...
271−instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
272− => HasServer (QueryParam sym a :> sublayout) context where
271+instance (KnownSymbol sym, FromHttpApiData a, HasServer api context)
272+ => HasServer (QueryParam sym a :> api) context where
273273
274− type ServerT (QueryParam sym a :> sublayout) m =
275− Maybe a -> ServerT sublayout m
274+ type ServerT (QueryParam sym a :> api) m =
275+ Maybe a -> ServerT api m
276276
277277 route Proxy context subserver =
278278 let querytext r = parseQueryText $ rawQueryString r
@@ -282,7 +282,7 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
282282 Just Nothing -> Nothing -- param present with no value -> Nothing
283283 Just (Just v) -> parseQueryParamMaybe v -- if present, we try to convert to
284284 -- the right type
285− in route (Proxy :: Proxy sublayout) context (passToServer subserver param)
285+ in route (Proxy :: Proxy api) context (passToServer subserver param)
286286 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
287287
288288-- | If you use @'QueryParams' "authors" Text@ in one of the endpoints for your API,
@@ -304,11 +304,11 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
304304-- > server = getBooksBy
305305-- > where getBooksBy :: [Text] -> Handler [Book]
306306-- > getBooksBy authors = ...return all books by these authors...
307−instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
308− => HasServer (QueryParams sym a :> sublayout) context where
307+instance (KnownSymbol sym, FromHttpApiData a, HasServer api context)
308+ => HasServer (QueryParams sym a :> api) context where
309309
310− type ServerT (QueryParams sym a :> sublayout) m =
311− [a] -> ServerT sublayout m
310+ type ServerT (QueryParams sym a :> api) m =
311+ [a] -> ServerT api m
312312
313313 route Proxy context subserver =
314314 let querytext r = parseQueryText $ rawQueryString r
@@ -317,7 +317,7 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
317317 -- corresponding values
318318 parameters r = filter looksLikeParam (querytext r)
319319 values r = mapMaybe (convert . snd) (parameters r)
320− in route (Proxy :: Proxy sublayout) context (passToServer subserver values)
320+ in route (Proxy :: Proxy api) context (passToServer subserver values)
321321 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
322322 looksLikeParam (name, _) = name == paramname || name == (paramname <> "[]")
323323 convert Nothing = Nothing
@@ -335,11 +335,11 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
335335-- > server = getBooks
336336-- > where getBooks :: Bool -> Handler [Book]
337337-- > getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
338−instance (KnownSymbol sym, HasServer sublayout context)
339− => HasServer (QueryFlag sym :> sublayout) context where
338+instance (KnownSymbol sym, HasServer api context)
339+ => HasServer (QueryFlag sym :> api) context where
340340
341− type ServerT (QueryFlag sym :> sublayout) m =
342− Bool -> ServerT sublayout m
341+ type ServerT (QueryFlag sym :> api) m =
342+ Bool -> ServerT api m
343343
344344 route Proxy context subserver =
345345 let querytext r = parseQueryText $ rawQueryString r
@@ -347,7 +347,7 @@ instance (KnownSymbol sym, HasServer sublayout context)
347347 Just Nothing -> True -- param is there, with no value
348348 Just (Just v) -> examine v -- param with a value
349349 Nothing -> False -- param not in the query string
350− in route (Proxy :: Proxy sublayout) context (passToServer subserver param)
350+ in route (Proxy :: Proxy api) context (passToServer subserver param)
351351 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
352352 examine v | v == "true" || v == "1" || v == "" = True
353353 | otherwise = False
@@ -392,14 +392,14 @@ instance HasServer Raw context where
392392-- > server = postBook
393393-- > where postBook :: Book -> Handler Book
394394-- > postBook book = ...insert into your db...
395−instance ( AllCTUnrender list a, HasServer sublayout context
396− ) => HasServer (ReqBody list a :> sublayout) context where
395+instance ( AllCTUnrender list a, HasServer api context
396+ ) => HasServer (ReqBody list a :> api) context where
397397
398− type ServerT (ReqBody list a :> sublayout) m =
399− a -> ServerT sublayout m
398+ type ServerT (ReqBody list a :> api) m =
399+ a -> ServerT api m
400400
401401 route Proxy context subserver =
402− route (Proxy :: Proxy sublayout) context (addBodyCheck subserver bodyCheck)
402+ route (Proxy :: Proxy api) context (addBodyCheck subserver bodyCheck)
403403 where
404404 bodyCheck = withRequest $ \ request -> do
405405 -- See HTTP RFC 2616, section 7.2.1
@@ -416,15 +416,15 @@ instance ( AllCTUnrender list a, HasServer sublayout context
416416 Just (Right v) -> return v
417417
418418-- | Make sure the incoming request starts with @"/path"@, strip it and
419−-- pass the rest of the request path to @sublayout@.
420−instance (KnownSymbol path, HasServer sublayout context) => HasServer (path :> sublayout) context where
419+-- pass the rest of the request path to @api@.
420+instance (KnownSymbol path, HasServer api context) => HasServer (path :> api) context where
421421
422− type ServerT (path :> sublayout) m = ServerT sublayout m
422+ type ServerT (path :> api) m = ServerT api m
423423
424424 route Proxy context subserver =
425425 pathRouter
426426 (cs (symbolVal proxyPath))
427− (route (Proxy :: Proxy sublayout) context subserver)
427+ (route (Proxy :: Proxy api) context subserver)
428428 where proxyPath = Proxy :: Proxy path
429429
430430instance HasServer api context => HasServer (RemoteHost :> api) context where