Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A ClojureScript library for Client/Server interaction

branch: master

update for more recent cljs

Signed-off-by: Chris Granger <ibdknox@gmail.com>
latest commit 604037c11c
Chris Granger authored
Octocat-spinner-32 src update for more recent cljs July 19, 2013
Octocat-spinner-32 test initial import February 04, 2012
Octocat-spinner-32 .gitignore initial import February 04, 2012
Octocat-spinner-32 README.md Remove mention of wrap-remotes from README.md. April 17, 2012
Octocat-spinner-32 project.clj update for more recent cljs July 19, 2013
README.md

fetch

A ClojureScript library that makes client/server interaction painless.

Usage

Remotes

Remotes let you make calls to a noir server without having to think about XHR. On the client-side you simply have code that looks like this:

(ns playground.client.test
  (:require [fetch.remotes :as remotes])
  (:require-macros [fetch.macros :as fm]))

(fm/remote (adder 2 5 6) [result]
  (js/alert result))

(fm/remote (get-user 2) [{:keys [username age]}]
  (js/alert (str "Name: " username ", Age: " age)))

;; for a much nicer experience, use letrem
(fm/letrem [a (adder 3 4)
            b (adder 5 6)]
    (js/alert (str "a: " a " b: " b)))

Note that the results we get are real Clojure datastructures and so we use them just as we would in normal Clojure code. No JSON here.

The noir side of things is just as simple. All you do is declare a remote using defremote.

(use 'noir.fetch.remotes)

(defremote adder [& nums]
           (apply + nums))

(defremote get-user [id]
           {:username "Chris"
            :age 24})

(server/start 8080)

License

Copyright (C) 2012 Chris Granger

Distributed under the Eclipse Public License, the same as Clojure.

Something went wrong with that request. Please try again.