Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nervous-systems/kvlt
Multi-target Clojure/script HTTP client
https://github.com/nervous-systems/kvlt
Last synced: 3 months ago
JSON representation
Multi-target Clojure/script HTTP client
- Host: GitHub
- URL: https://github.com/nervous-systems/kvlt
- Owner: nervous-systems
- License: unlicense
- Archived: true
- Created: 2015-12-12T13:23:55.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-01-19T08:26:36.000Z (almost 7 years ago)
- Last Synced: 2024-07-09T09:05:40.588Z (4 months ago)
- Language: Clojure
- Size: 76.2 KB
- Stars: 69
- Watchers: 5
- Forks: 8
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-clojure - kvlt
README
![Hail Satan](https://raw.githubusercontent.com/nervous-systems/kvlt/master/doc/assets/kvlt.png) [![Build Status](https://travis-ci.org/nervous-systems/kvlt.svg?branch=master)](https://travis-ci.org/nervous-systems/kvlt)
Attempts to present a uniform, asychronous client interface for HTTP across JVM / Node / browsers.
[Latest documentation / examples](//nervous.io/doc/kvlt)
[![Clojars Project](http://clojars.org/io.nervous/kvlt/latest-version.svg)](http://clojars.org/io.nervous/kvlt)
### Features
- Supports Clojure/JVM, Clojurescript/Node and Clojurescript/Browser
- Individual deferred values are exposed via promises ([kvlt.core](//nervous.io/doc/kvlt/kvlt.core.html)), or asynchronous channels ([kvlt.chan](//nervous.io/doc/kvlt/kvlt.chan.html))
- `core.async`-based support for Websockets and Server-sent Events
- Raw responses available as Javascript typed arrays (on Node, and in browsers with [XHR Level 2](https://www.w3.org/TR/XMLHttpRequest2/) support)
- Ring-like API### Requirements
- Clojure use requires JDK8
### Todo / Notes
- Automated/CI testing is currently limited to JVM, Node and recent Chrome & Firefox builds
- No support for streamed requests/responses. Open to suggestions about how this might be handled across platforms
- Young project, etc. - please file issues# Examples
[kvlt.core/request!](//nervous.io/doc/kvlt/kvlt.core.html#var-request.21)
returns a [promesa](https://github.com/funcool/promesa) promise, which
can be manipulated using promise-specific (e.g. `promesa/then`)
operations, or treated as a monad using the primitives from
[cats](https://github.com/funcool/cats). Below, we're working with
something like:```clojure
(ns kvlt.examples
(:require [kvlt.core :as kvlt]
[promesa.core :as p]))
```The default `:method` is `:get`:
```clojure
(p/alet [{:keys [status]} (p/await (kvlt/request! {:url url}))]
(is (= status 200)))
```## Explicit Callback
```clojure
(p/then
(kvlt/request! {:url url})
(fn [{:keys [status]}]
(is (= status 200))))
```## core.async
The [kvlt.chan](//nervous.io/doc/kvlt/kvlt.chan.html) namespace
parallels the promise-driven `kvlt.core`, using asynchronous channels
to communicate deferred values.```clojure
(go
(let [{:keys [status]} (! ws {:climate :good, :bribery :tolerated})
(let [instructions (