https://github.com/swlkr/snap
Global atom state changes into restful urls
https://github.com/swlkr/snap
clojurescript rest
Last synced: about 1 month ago
JSON representation
Global atom state changes into restful urls
- Host: GitHub
- URL: https://github.com/swlkr/snap
- Owner: swlkr
- License: mit
- Created: 2016-08-19T15:41:57.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-10-01T19:31:11.000Z (over 9 years ago)
- Last Synced: 2025-01-15T10:08:22.150Z (over 1 year ago)
- Topics: clojurescript, rest
- Language: Clojure
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
snap
======================
Turns your global state atom changes into restful urls
Pull requests are welcome!
Usage
-----
In your `project.clj`, add the following dependency:
```clojure
[snap "1.0.0"]
```
Then, set up your remotes, global state and, oh snap! restful http requests from state changes!
```clojure
(ns foo
(:require [snap.core :as snap]))
; Define the restful urls for each key in the global state atom
(def remotes {:posts {:get "/posts"
:put "/posts/:id"
:post "/posts"
:delete "/posts/:id"}
:post {:get "/posts/:id"}})
(def app-state {:posts [{:id 1 :title "Hodor" :content "Hodor hodor hodor"}]})
(def new-state (update-in app-state [:posts] conj {:id 2 :title "Hodor hodor" :content "Hodor"})
(snap/diff app-state new-state remotes)
[{:url "/posts"
:method :post
:body {:id 2 :title "Hodor hodor" :content "Hodor"}
:path [:posts 1]}]
```
Development
-----
```bash
git clone git@github.com:swlkr/snap.git
cd snap
lein deps
```
Then start hacking!
Tests
-----
```bash
lein doo node test
```