Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: ed23018703
Fetching contributors…

Cannot retrieve contributors at this time

48 lines (32 sloc) 2.1 KB


This is a Clojure implementation of the SPORE specification for RESTful clients. It uses spec files to generate functions calling http routes on a server. See this post and this one for more information or read the specification for even greater details. This SPORE implementation is build upon the existing clj-http library and is middleware-compatible with it.


For the most basic case:

(use 'clj-spore)
(use 'clj-spore.middleware)

(let [client (load-spec-from-file "test/ihackernews.json"
                                  :middlewares [wrap-json-format])
      res ((client :askhn_posts) :nextid "FiNf744LLx")]
  (if (= (res :status) 200)
    (doseq [item (get-in [:decoded-body "items"] res)]
      (println (item "title")))))

load-spec-from-file takes a file path to the spec and optionally a list of middlewares and an :overload param that can be used to overload spec params, like this:

(def client (load-spec-from-file "test/ihackernews.json"
                                  :middlewares [wrap-json-format]
                                  :overload {:base_url "http://localhost:8765"}))

The body of the request is given by the :payload arg and :middlewares can contain more complex instanciation, like so:

(def client (load-spec-from-file "test/ihackernews.json" :middlewares [[wrap-clojure-response
                                                                        :enabled-if #(not= (:path %) "/login")
                                                                        :args [:type "application/x-clojure"]]]))

You can check the tests to see more use cases and read the docstrings of the functions to go further.



Copyright (C) 2011 Nils Grunwald

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

Jump to Line
Something went wrong with that request. Please try again.