by xeqi

xeqi /peridot

a basic api for interacting with ring apps

130 Stars 19 Forks Last release: 10 months ago (v0.5.2) 161 Commits 23 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

peridot Build Status Dependencies Status

peridot is an interaction library for ring apps. Its functionality is based on an partial port of Rack::Test's test suite.

Dependency Information

Clojars Project

peridot's latest version and information on how to install it is available from clojars.


The api namespace is

. If you are using peridot in tests you may want to have
(:use [peridot.core])
in your
declaration. All examples below assume so.

peridot is designed to be used with ->, and maintains cookies across requests in the threading.


You can create an initial state with

(session ring-app) ;Use your ring app


You can use

to send a request to your ring app.
(-> (session ring-app) ;Use your ring app
    (request "/")
    (request "/search" :request-method :post
                       :params {:q "clojure"}))

It will use

by default. Options should be from the request map portion of the ring spec.

should not be nested. Most params will be sent as
(str value)
. If a value is a
then peridot will send the request as a multipart form using the contents of the file.

peridot will not follow redirects automatically. To follow a redirect use

. This will throw an
when the last response was not a redirect.
(-> (session ring-app) ;Use your ring app
    (request "/login" :request-method :post
                      :params {:username "someone"
                               :password "password"})

By default, when

ing data, params will be encoded as
. If you want to use an alternative encoding, you can pass
as an option, and use
instead of
(-> (session ring-app) ;Use your ring app
    (request "/login" :request-method :post
                      :content-type "application/xml"
                      :body ""))


peridot will manage cookies through the threading. This allows you to login and perform actions as that user.

(-> (session ring-app) ;Use your ring app
    (request "/login" :request-method :post
                      :params {:username "someone"
                               :password "password"})
    (request "/tasks")
    (request "/tasks/create" ...)
    (request "/tasks/1")

Persistent Information

It can be useful to set persistent information across requests.

will set a header.
will use basic authentication.
will set the content-type.
(-> (session ring-app) ;Use your ring app
    (header "User-Agent" "Firefox")
    (authorize "bryan" "secret")
    (content-type "application/json")
    (request "/tasks/create" :request-method :put
                             :body some-json))


The state information returned by each function has

for information from the last interaction with the ring app.

Transactions and database setup

peridot runs without an http server and, depending on your setup, transactions can be used to rollback and isolate tests. Some fixtures may be helpful:

(use-fixtures :once
              (fn [f]
                ( db (f))))
(use-fixtures :each
              (fn [f]


leiningen version 2 is used as the build tool.

lein2 all test
will run the test suite against clojure 1.3, 1.4 and 1.5.1.


Copyright (C) 2013 Nelson Morris and contributors

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.