Skip to content

Commit

Permalink
Testing interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Apr 18, 2024
1 parent 8723c67 commit 2b8ca23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Babashka [http-client](https://github.com/babashka/http-client): HTTP client for Clojure and babashka built on java.net.http

## 0.4.18 (2024-04-18)

- Support a Clojure function as `:client` option, mostly useful for testing

## 0.4.17 (2024-04-12)

- [#49](https://github.com/babashka/http-client/issues/49): add `::oauth-token` interceptor
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ function is executed on the response. Default interceptors are in
configured on the level of requests by passing a modified `:interceptors`
chain.
#### Testing interceptors
For testing interceptors it can be useful to use the `:client` option in combination with a
Clojure function. When passing a function, the request won't be converted to a
`java.net.http.Request` but just passed as a ring request to the function. The
function is expected to return a ring response:
``` clojure
(http/get "https://clojure.org" {:client (fn [req] {:body 200})})
```
### Async
To execute request asynchronously, use `:async true`. The response will be a
Expand Down Expand Up @@ -375,7 +386,7 @@ Here is a code snippet for `deps.edn`
{:jvm-opts
[;; enable logging for java.net.http
"-Djdk.httpclient.HttpClient.log=errors,requests,headers,frames[:control:data:window:all..],content,ssl,trace,channel"]}
}}
}}
```
## Test
Expand Down

0 comments on commit 2b8ca23

Please sign in to comment.