Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/onionpancakes/hop
Minimal wrapper around the JDK HttpClient
https://github.com/onionpancakes/hop
client http
Last synced: 11 days ago
JSON representation
Minimal wrapper around the JDK HttpClient
- Host: GitHub
- URL: https://github.com/onionpancakes/hop
- Owner: onionpancakes
- License: mit
- Created: 2022-02-15T07:20:11.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-06-26T08:02:00.000Z (5 months ago)
- Last Synced: 2024-06-27T09:09:03.956Z (5 months ago)
- Topics: client, http
- Language: Clojure
- Homepage:
- Size: 111 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hop
Minimal wrapper for Java's [HttpClient](https://docs.oracle.com/en/java/javase/21/docs/api/java.net.http/java/net/http/package-summary.html).
# Status
[![Run tests](https://github.com/onionpancakes/hop/actions/workflows/run_tests.yml/badge.svg)](https://github.com/onionpancakes/hop/actions/workflows/run_tests.yml)
Currently for my personal use. Future breaking changes possible.
# Deps
Add to deps.edn
```clojure
{:deps
{dev.onionpancakes/hop
{:git/url "https://github.com/onionpancakes/hop"
:git/sha ""}}}
```# Examples
### GET
```clojure
(require '[dev.onionpancakes.hop.client :as hop])(hop/send "http://www.example.com")
(hop/send {:uri "http://www.example.com"} :input-stream)
```### POST
```clojure
(hop/send {:method :POST
:uri "http://www.example.com"
:body "my post data"})
```# Usage
Require the namespace.
```clojure
(require '[dev.onionpancakes.hop.client :as hop])
```## Send Requests
Send some request.
* First arg is a request map. Strings are accepted as shorthand as `{:uri }`.
* Second arg is a `BodyHandler`. When omitted, defaults to `:byte-array`.```clojure
(def resp
(hop/send {:uri "http://www.example.com"}))
```Read the response as a lookup map.
```clojure
(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
Set accept-encoding manually.
```clojure
(def resp
(hop/send {:uri "http://www.example.com"
:headers {:accept-encoding "gzip"}}))
```### Decompress
```clojure
(require '[dev.onionpancakes.hop.io :as io])(slurp (io/decompress (:body resp) "gzip"))
```# License
Released under the MIT License.