Skip to content

Commit 5d30010

Browse files
committed
add reference to servant-flatten
1 parent 74b6461 commit 5d30010

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

doc/cookbook/structuring-apis/StructuringApis.lhs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ a server for `FactoringAPI` (without the `'`) reflects the
6666
server must be a function that takes an `Int` (the `Capture`) and
6767
returns two values glued with `:<|>`, one of type `Maybe Int -> Handler Int`
6868
and the other of type `Handler Int`. Let's provide such a server
69-
implementation.
69+
implementation, with those "nested types".
7070
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
7272
type that `Server FactoringAPI` "resolves to" by typing
7373
`:kind! Server FactoringAPI`.
7474
@@ -82,6 +82,16 @@ factoringServer x = getXY :<|> postX
8282
postX = return (x - 1)
8383
```
8484
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+
8595
Next come the two sub-APIs defined in terms of this `SimpleAPI`
8696
type, but with different parameters. That type is just a good old
8797
Haskell type synonym that abstracts away a pretty common structure in

0 commit comments

Comments
 (0)