You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: servant-foreign/src/Servant/Foreign.hs
+22-19Lines changed: 22 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,32 @@
1
1
--| Generalizes all the data needed to make code generation work with
2
2
-- arbitrary programming languages.
3
+
--
4
+
-- See documentation of 'HasForeignType' for a simple example. 'listFromAPI' returns a list of all your endpoints and their foreign types, given a mapping from Haskell types to foreign types (conventionally called `ftypes` below).
--| Full description of an endpoint in your API, generated by 'listFromAPI'. It should give you all the information needed to generate foreign language bindings.
190
+
--
191
+
-- Every field containing @ftype@ will use the foreign type mapping specified via 'HasForeignType' (see its docstring on how to set that up).
192
+
--
193
+
-- See https://docs.servant.dev/en/stable/tutorial/ApiType.html for accessible documentation of the possible content of an endpoint.
194
+
dataReqftype=Req
195
+
{_reqUrl::Urlftype
196
+
--^ Full list of URL segments, including captures
137
197
, _reqMethod::HTTP.Method
138
-
, _reqHeaders:: [HeaderArgf]
139
-
, _reqBody::Maybef
140
-
, _reqReturnType::Maybef
198
+
--^ @\"GET\"@\/@\"POST\"@\/@\"PUT\"@\/…
199
+
, _reqHeaders:: [HeaderArgftype]
200
+
--^ Headers required by this endpoint, with their type
201
+
, _reqBody::Maybeftype
202
+
--^ Foreign type of the expected request body ('ReqBody'), if any
203
+
, _reqReturnType::Maybeftype
204
+
--^ The foreign type of the response, if any
141
205
, _reqFuncName::FunctionName
206
+
--^ The URL segments rendered in a way that they can be easily concatenated into a canonical function name
142
207
, _reqBodyContentType::ReqBodyContentType
208
+
--^ The content type the request body is transferred as.
209
+
--
210
+
-- This is a severe limitation of @servant-foreign@ currently,
211
+
-- as we only allow the content type to be `JSON`
212
+
-- no user-defined content types. ('ReqBodyMultipart' is not
213
+
-- actually implemented.)
214
+
--
215
+
-- Thus, any routes looking like this will work:
216
+
--
217
+
-- @"foo" :> Get '[JSON] Foo@
218
+
--
219
+
-- while routes like
220
+
--
221
+
-- @"foo" :> Get '[MyFancyContentType] Foo@
222
+
--
223
+
-- will fail with an error like
224
+
--
225
+
-- @• JSON expected in list '[MyFancyContentType]@
0 commit comments