git.iko.soy/typeable/servant
on master help sign in
add reference to servant-flatten
5d30010Alp Mestanogullari
doc/cookbook/structuring-apis/StructuringApis.lhs+12−2
@@ -66,9 +66,9 @@ a server for `FactoringAPI` (without the `'`) reflects the
66server must be a function that takes an `Int` (the `Capture`) and
66server must be a function that takes an `Int` (the `Capture`) and
67returns two values glued with `:<|>`, one of type `Maybe Int -> Handler Int`
67returns two values glued with `:<|>`, one of type `Maybe Int -> Handler Int`
68and the other of type `Handler Int`. Let's provide such a server
68and the other of type `Handler Int`. Let's provide such a server
69−implementation.
69+implementation, with those "nested types".
70
70
71−_Note_: you can load this module in ghci and ask for the concrete
71+**Tip**: you can load this module in ghci and ask for the concrete
72type that `Server FactoringAPI` "resolves to" by typing
72type that `Server FactoringAPI` "resolves to" by typing
73`:kind! Server FactoringAPI`.
73`:kind! Server FactoringAPI`.
74
74
@@ -82,6 +82,16 @@ factoringServer x = getXY :<|> postX
82 postX = return (x - 1)
82 postX = return (x - 1)
83```
83```
84
84
85+If you want to avoid the "nested types" and the need to manually
86+dispatch the arguments (like `x` above) to the different request
87+handlers, and would just like to be able to declare the API type
88+as above but pretending that the `Capture` is not factored out,
89+that every combinator is "distributed" (i.e that all endpoints
90+are specified like `FactoringAPI'` above), then you should
91+look at `flatten` from the
92+[servant-flatten](https://hackage.haskell.org/package/servant-flatten)
93+package.
94+
85Next come the two sub-APIs defined in terms of this `SimpleAPI`
95Next come the two sub-APIs defined in terms of this `SimpleAPI`
86type, but with different parameters. That type is just a good old
96type, but with different parameters. That type is just a good old
87Haskell type synonym that abstracts away a pretty common structure in
97Haskell type synonym that abstracts away a pretty common structure in