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
* Simplify code in CurlMock cookbook recipe
* Link to latest versions of packages on hackage
* Fix grammar in the OpenIdConnect recipe
* HasForeignType -> HasForeign
Copy file name to clipboardExpand all lines: doc/cookbook/curl-mock/CurlMock.lhs
+7-19Lines changed: 7 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ listFromAPI :: (HasForeign lang ftype api, GenerateList ftype (Foreign ftype api
86
86
```
87
87
88
88
This 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.
90
90
We will not go into details here, but this allows us to create a value of type `ftype` for any type `a` in our API.
91
91
92
92
In our case we want to create a mock of every type `a`.
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.
151
139
152
140
``` haskell
153
141
generateEndpoint :: Text -> Req Mocked -> IO Text
@@ -169,7 +157,7 @@ generateEndpoint host req =
169
157
`servant-foreign` offers a multitude of lenses to be used with `Req`-values.
170
158
171
159
`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).
173
161
174
162
But how do we get our mocked json string? This seems to be a bit to short to be true:
175
163
@@ -201,7 +189,7 @@ And now, lets hook it all up in our main function:
201
189
``` haskell
202
190
main :: IO ()
203
191
main =
204
-
generateCurl api "localhost:8081" >>= (\v -> T.IO.putStrLn v)
192
+
generateCurl api "localhost:8081" >>= T.IO.putStrLn
205
193
```
206
194
207
195
Done:
@@ -213,6 +201,6 @@ curl -X POST -d '{"email":"wV_b:z!(3DM V","age":10,"name":"=|W"}
213
201
```
214
202
215
203
This 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.
217
205
218
206
Also, we now know how to use `HasForeignType` and `listFromAPI` to generate anything we want.
Copy file name to clipboardExpand all lines: doc/cookbook/sentry/Sentry.lhs
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ In the second step it actually sends our message to Sentry with the `register` f
86
86
87
87
- the configured Sentry service which we just created
88
88
- the name of the logger
89
-
- the error level (see [SentryLevel](https://hackage.haskell.org/package/raven-haskell-0.1.2.0/docs/System-Log-Raven-Types.html#t:SentryLevel) for the possible options)
89
+
- the error level (see [SentryLevel](https://hackage.haskell.org/package/raven-haskell/docs/System-Log-Raven-Types.html#t:SentryLevel) for the possible options)
90
90
- the message we want to send
91
91
- an update function to handle the specific `SentryRecord`
0 commit comments