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
I spend some considerable time reverse engineering the module, so I
thought I’d write the documentation I would have liked to see.
The strategy here is that a user not necessarily has insight into how
servant works internally, or even how to write complex servant routes,
they just want to generate a list of endpoints and convert the `Req`
type into e.g. generated code in $language. Thus, they need to know
the semantics of all fields of Req, how they interact and how they
relate to a plain http route.
I made sure every `f` is replaced with `ftype`, so we have one
conventional way of referring to the foreign type argument everywhere.
Some enums are not set at all, they are marked as such.
`_reqBodyContentType` introduces a major restriction of the module, so
that is mentioned in the documentation for now, until the time it will
be fixed.
A few TODO’s describe places where types don’t make sense but would
introduce API-breaking changes, so these should probably be
simplified,
but bundled in one go.
Copy file name to clipboardExpand all lines: servant-foreign/src/Servant/Foreign.hs
+14-12Lines changed: 14 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -3,28 +3,30 @@
3
3
--
4
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
133
197
, _reqMethod::HTTP.Method
134
-
, _reqHeaders:: [HeaderArgf]
135
-
, _reqBody::Maybef
136
-
, _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
137
205
, _reqFuncName::FunctionName
206
+
--^ The URL segments rendered in a way that they can be easily concatenated into a canonical function name
138
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