Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 47 lines (32 sloc) 2.15 kb
6e55b934 » ngrunwald
2010-09-16 initial commit
1 # clj-spore
2
027331bd » ngrunwald
2011-09-23 added README
3 This is a Clojure implementation of the [SPORE](https://github.com/SPORE/specifications) specification for RESTful clients. It uses spec files to generate functions calling http routes on a server. See [this post](http://lumberjaph.net/misc/2010/09/17/spore.html) and [this one](http://lumberjaph.net/misc/2010/10/20/spore-update.html) for more information or read the [specification](https://github.com/SPORE/specifications) for even greater details. This SPORE implementation is build upon the existing [clj-http](https://github.com/mmcgrana/clj-http) library and is middleware-compatible with it.
6e55b934 » ngrunwald
2010-09-16 initial commit
4
5 ## Usage
6
027331bd » ngrunwald
2011-09-23 added README
7 For the most basic case:
6e55b934 » ngrunwald
2010-09-16 initial commit
8
027331bd » ngrunwald
2011-09-23 added README
9 ```clojure
10 (use 'clj-spore)
11 (use 'clj-spore.middleware)
6e55b934 » ngrunwald
2010-09-16 initial commit
12
027331bd » ngrunwald
2011-09-23 added README
13 (let [client (load-spec-from-file "test/ihackernews.json"
14 :middlewares [wrap-json-format])
15 res ((client :askhn_posts) :nextid "FiNf744LLx")]
16 (if (= (res :status) 200)
17 (doseq [item (get-in [:decoded-body "items"] res)]
18 (println (item "title")))))
19 ```
20
21 _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:
22
23 ```clojure
24 (def client (load-spec-from-file "test/ihackernews.json"
25 :middlewares [wrap-json-format]
26 :overload {:base_url "http://localhost:8765"}))
27 ```
28
29 The body of the request is given by the :payload arg and :middlewares can contain more complex instanciation, like so:
30
31 ```clojure
32 (def client (load-spec-from-file "test/ihackernews.json" :middlewares [[wrap-clojure-response
33 :enabled-if #(not= (:path %) "/login")
34 :args [:type "application/x-clojure"]]]))
35 ```
36
37 You can check the tests to see more use cases and read the docstrings of the functions to go further.
38
39 ## Thanks
40
41 - [Linkfluence](http://us.linkfluence.net/) for sponsoring this work.
6e55b934 » ngrunwald
2010-09-16 initial commit
42
43 ## License
44
027331bd » ngrunwald
2011-09-23 added README
45 Copyright (C) 2011 Nils Grunwald
6e55b934 » ngrunwald
2010-09-16 initial commit
46
47 Distributed under the Eclipse Public License, the same as Clojure.
Something went wrong with that request. Please try again.