Skip to content
Helper for faking clj-http requests.
Latest commit d956a6c Apr 1, 2016 @myfreeweb Merge pull request #27 from gfredericks/compare-parsed-query-params
Compare parsed query params

clj-http-fake Build Status MIT License

Basically, fakeweb in Clojure, for clj-http.


In your project.clj file:

Clojars Project

In your namespace declaration:

(ns myapp.test.core
  (:require [clj-http.client :as c])
  (:use clj-http.fake))

Basic operations:

(with-fake-routes {
  ;; Exact string match:
  "" (fn [request] {:status 200 :headers {} :body "Hey, do I look like"})
  ;; matches (c/get "")

  ;; Exact string match with query params:
  "" (fn [request] {:status 200 :headers {} :body "Nah, that can't be Google!"})
  ;; matches (c/get "" {:query-params {:query "param"}})

  ;; Regexp match:
  #"https://([a-z]+)" (fn [req] {:status 200 :headers {} :body "Hello world"})
  ;; matches (c/get ""), (c/get "") and so on, based on regexp.

  ;; Match based an HTTP method:
  "" {:get (fn [req] {:status 200 :headers {} :body "What is Scmoogle anyways?"})}
  ;; will match only (c/get "")

  ;; Match multiple HTTP methods:
  "" {:get    (fn [req] {:status 200 :headers {} :body "Nah, that can't be Google!"})
                        :delete (fn [req] {:status 401 :headers {} :body "Do you think you can delete me?!"})}

  ;; Match using query params as a map
   {:address ""
    :query-params {:q "aardark"}} (fn [req] {:status 200 :headers {} :body "Searches have results"})
 ;; Your tests with requests here


Use Leiningen with profiles.

There are aliases to run the tests with the oldest and newest supported versions of clj-http:

$ lein test-newest
$ lein test-oldest


Released under the MIT License.


Something went wrong with that request. Please try again.