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
Hato is wrapping JDK 11's [HttpClient](https://openjdk.java.net/groups/net/httpclient/intro.html).
12
-
13
11
It supports both HTTP/1.1 and HTTP/2, with synchronous and asynchronous execution modes as well as websockets.
14
12
15
-
In general, it will feel familiar to users of http clients like [clj-http](https://github.com/dakrone/clj-http).
13
+
In general, it will feel familiar to users of http clients like [clj-http](https://github.com/dakrone/clj-http), while Hato is wrapping JDK 11's [HttpClient](https://openjdk.java.net/groups/net/httpclient/intro.html) instead of the [org.apache.httpcomponents](http://hc.apache.org), and not brining a server along also as [http-kit](https://github.com/http-kit/http-kit). This is a fork of [hato](https://github.com/gnarroway/hato).
14
+
16
15
The API is designed to be idiomatic and to make common tasks convenient, whilst
17
16
still allowing the underlying HttpClient to be configured via native Java objects.
18
17
@@ -23,12 +22,12 @@ Please try it out and raise any issues you may find.
23
22
24
23
## Installation
25
24
26
-
hato requires JDK 11 and above. If you are running an older version of Java, please look at [clj-http](https://github.com/dakrone/clj-http).
25
+
hato requires JDK 11 and above. If you are running an older version of Java, please look at [clj-http](https://github.com/dakrone/clj-http) instead.
27
26
28
27
For Leiningen, add this to your project.clj
29
28
30
29
```clojure
31
-
[hato "0.5.0"]
30
+
[gorillalabs/hato "RELEASE"]
32
31
```
33
32
34
33
## Quickstart
@@ -152,21 +151,15 @@ request and returns a response. Convenience wrappers are provided for the http v
152
151
`as` Return response body in a certain format. Valid options:
153
152
154
153
- Return an object type: `:string` (default), `:byte-array`, `:stream`, `:discarding`,
155
-
- Coerce response body with certain format: `:json`, `:json-string-keys`,
156
-
`:json-strict`, `:json-strict-string-keys`, `:clojure`, `:transit+json`, `:transit+msgpack`. JSON and transit
157
-
coercion require optional dependencies [cheshire](https://github.com/dakrone/cheshire) and
158
-
[com.cognitect/transit-clj](https://github.com/cognitect/transit-clj) to be installed, respectively.
154
+
- Coerce response body with certain format: `:edn`, `:json`, `:transit+json`, `:transit+msgpack` with the help of [gorillalabs/muuntaja](https://github.com/gorillalabs/muuntaja).
159
155
- A [`java.net.http.HttpRequest$BodyHandler`](https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpResponse.BodyHandler.html).
160
156
Note that decompression is enabled by default but only handled for the options above. A custom BodyHandler
161
157
may require opting out of compression, or implementing a multimethod specific to the handler.
162
-
163
-
`coerce` Determine which status codes to coerce response bodies. `:unexceptional` (default), `:always`, `:exceptional`.
164
-
This presently only has an effect for json coercions.
165
158
166
159
`query-params` A map of options to turn into a query string. See usage examples for details.
167
160
168
161
`form-params` A map of options that will be sent as the body, depending on the `content-type` option. For example,
169
-
set `:content-type :json` to coerce the form-params to a json string (requires [cheshire](https://github.com/dakrone/cheshire)).
162
+
set `:content-type :json` to coerce the form-params to a json string (using [gorillalabs/muuntaja](https://github.com/gorillalabs/muuntaja)).
170
163
See usage examples for details.
171
164
172
165
`multi-param-style` Decides how to represent array values when converting `query-params` into a query string. Accepts:
@@ -309,7 +302,7 @@ As a convenience, nesting can also be controlled by `:flatten-nested-keys`:
309
302
310
303
### Output coercion
311
304
312
-
hato performs output coercion of the response body, returning a string by default.
305
+
You can control whether you like hato to return an `InputStream` (using `:as :stream`), `byte-array` (using `:as :byte-array`) or `String` (`:as String`) with no further coercion.
313
306
314
307
```clojure
315
308
; Returns a string response
@@ -320,32 +313,51 @@ hato performs output coercion of the response body, returning a string by defaul
320
313
321
314
; Returns an InputStream
322
315
(hc/get"http://moo.com" {:as:stream})
316
+
```
323
317
324
-
; Coerces clojure strings
325
-
(hc/get"http://moo.com" {:as:clojure})
318
+
If you do not state an `:as` (or give it any other value), hato performs output coercion of the response body based upon the content type header. So, what you're looking for here is the accept header and a friendly web server listening to whatever you like best.
By default, hato only coerces JSON responses for unexceptional statuses. Control this with the `:coerce` option:
333
+
Do add new content types or alter existing ones, you can pass a [muuntaja instance or muuntaja options](https://github.com/gorillalabs/muuntaja#configuration) using the `:muuntaja` key:
343
334
344
-
```clojure
345
-
:unexceptional ; default - only coerce response bodies for unexceptional status codes
346
-
:exceptional ; only coerce for exceptional status codes
0 commit comments