@@ -86,7 +86,7 @@ listFromAPI :: (HasForeign lang ftype api, GenerateList ftype (Foreign ftype api
8686```
8787
8888This looks a bit confusing...
89−[Here](https://hackage.haskell.org/package/servant-foreign-0.11.1/docs/Servant-Foreign.html#t:HasForeignType) is the documentation for the `HasForeign` typeclass.
89+[Here](https://hackage.haskell.org/package/servant-foreign/docs/Servant-Foreign.html#t:HasForeign) is the documentation for the `HasForeign` typeclass.
9090We will not go into details here, but this allows us to create a value of type `ftype` for any type `a` in our API.
9191
9292In our case we want to create a mock of every type `a`.
@@ -130,24 +130,12 @@ generateCurl :: (GenerateList Mocked (Foreign Mocked api), HasForeign NoLang Moc
130130generateCurl p host =
131131 fmap T.unlines body
132132 where
133− body = foldr (\endp curlCalls -> mCons (generateEndpoint host endp) curlCalls) (return [])
133+ body = mapM (generateEndpoint host)
134134 $ listFromAPI (Proxy :: Proxy NoLang) (Proxy :: Proxy Mocked) p
135135```
136136
137−To understand this function, better start at the end:
138−
139−`listFromAPI` gives us a list of endpoints. We iterate over them (`foldr`) and call `generateEndpoint` for every endpoint.
140−
141−As generate endpoint will not return `Text` but `IO Text` (remember we need some random bits to mock), we cannot just use the cons operator but need to build `IO [Text]` from `IO Text`s.
142−
143−``` haskell
144−mCons :: IO a -> IO [a] -> IO [a]
145−mCons ele list =
146− ele >>= \e -> list >>= \l -> return ( e : l )
147−```
148−
149−
150−Now comes the juicy part; accessing the endpoints data:
137+First, `listFromAPI` gives us a list of `Req Mocked`. Each `Req` describes one endpoint from the API type.
138+We generate a curl call for each of them using the following helper.
151139
152140``` haskell
153141generateEndpoint :: Text -> Req Mocked -> IO Text
@@ -169,7 +157,7 @@ generateEndpoint host req =
169157`servant-foreign` offers a multitude of lenses to be used with `Req`-values.
170158
171159`reqMethod` gives us a straigthforward `Network.HTTP.Types.Method`, `reqUrl` the url part and so on.
172−Just take a look at [the docs](https://hackage.haskell.org/package/servant-foreign-0.11.1/docs/Servant-Foreign.html).
160+Just take a look at [the docs](https://hackage.haskell.org/package/servant-foreign/docs/Servant-Foreign.html).
173161
174162But how do we get our mocked json string? This seems to be a bit to short to be true:
175163
@@ -201,7 +189,7 @@ And now, lets hook it all up in our main function:
201189``` haskell
202190main :: IO ()
203191main =
204− generateCurl api "localhost:8081" >>= (\v -> T.IO.putStrLn v)
192+ generateCurl api "localhost:8081" >>= T.IO.putStrLn
205193```
206194
207195Done:
@@ -213,6 +201,6 @@ curl -X POST -d '{"email":"wV_b:z!(3DM V","age":10,"name":"=|W"}
213201```
214202
215203This is of course no complete curl call mock generator, many things including path arguments are missing.
216−But it correctly generate mock calls for simple POST requests.
204+But it correctly generates mock calls for simple POST requests.
217205
218206Also, we now know how to use `HasForeignType` and `listFromAPI` to generate anything we want.