Skip to content

A smarter client-side with ClojureScript : Shoreleave's rpc/xhr/jsonp facilities

License

Notifications You must be signed in to change notification settings

shoreleave/shoreleave-remote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shoreleave

A smarter client-side in ClojureScript

###Shoreleave is a collection of integrated libraries that focuses on:

  • Security
  • Idiomatic interfaces
  • Common client-side strategies
  • HTML5 capabilities
  • ClojureScript's advantages

It builds upon efforts found in other ClojureScript projects, such as Fetch and ClojureScript:One.

Shoreleave-remote Overview

The remote namespace provides CSRF-protected and consistent interfaces for XHR, Pooled XHR, JSONP, and HTTP-RPC calls.

The CSRF protection is automatic if your Clojure server is using the ring-anti-forgery middleware.

The HTTP-RPC is built upon Fetch and allows for exposing a server-side namespace as a client-side API, via a single server-side call, remote-ns.

Please see the Marginalia docs for more information.


A typical Noir setup might look like:

(ns example
  (:require [noir.shoreleave.rpc :as rpc]))

;; ...

;; The Base Web Server
;; ---------------------
;; Serve every view file found in `src/example/views`
(server/load-views "src/example/views/")

;; Remote Namespaces
;; -----------------
(rpc/activate-remotes!)
(rpc/remote-ns 'example.api :as "api") ; Note, you don't have to include example.api in this .clj file

;; Middleware
;;-----------
(server/add-middleware ring.middleware.gzip/wrap-gzip)
(server/add-middleware ring.middleware.file-info/wrap-file-info)
(server/add-middleware ring.middleware.anti-forgery/wrap-anti-forgery)

You can also define single "global" rpc functions:

(defremote ping []
  (do
    (println "Pinged by client!")
    "PONG - from the server"))

Plays well with others

Shoreleave makes no assumptions about other libraries you might be using in your app.

I have found it to pair particularly well with Enfocus

Examples and usage

Please the github wiki for examples of each library feature

License

Copyright © 2012 Paul deGrandis

Distributed under the Eclipse Public License, the same as Clojure. Please see the LICENSE_epl.html for details.

About

A smarter client-side with ClojureScript : Shoreleave's rpc/xhr/jsonp facilities

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published