Minimal wrapper for Java's HttpClient.
Currently for my personal use. Future breaking changes possible.
Add to deps.edn
{:deps
{dev.onionpancakes/hop
{:git/url "https://github.com/onionpancakes/hop"
:git/sha "<GIT SHA>"}}}
(require '[dev.onionpancakes.hop.client :as hop])
(hop/send "http://www.example.com")
(hop/send {:uri "http://www.example.com"} :input-stream)
(hop/send {:method :POST
:uri "http://www.example.com"
:body "my post data"})
Require the namespace.
(require '[dev.onionpancakes.hop.client :as hop])
Send some request.
- First arg is a request map. Strings are accepted as shorthand as
{:uri <str value>}
. - Second arg is a
BodyHandler
. When omitted, defaults to:byte-array
.
(def resp
(hop/send {:uri "http://www.example.com"}))
Read the response as a lookup map.
(println (:status resp)) ; 200
(println (:headers resp)) ; { some headers map value }
(println (:body resp)) ; Default body data as byte-array
(println (:media-type resp)) ; "text/html"
(println (:character-encoding resp)) ; "UTF-8"
(println (:content-type resp)) ; "text/html; charset=UTF-8"
Set accept-encoding manually.
(def resp
(hop/send {:uri "http://www.example.com"
:headers {:accept-encoding "gzip"}}))
(require '[dev.onionpancakes.hop.io :as io])
(slurp (io/decompress (:body resp) "gzip"))
Released under the MIT License.