Skip to content


Subversion checkout URL

You can clone with
Download ZIP
An idiomatic clojure http client wrapping the apache client
Tree: c19149b675
Failed to load latest commit information.
src/clj_http provide default port number (80 or 443) in parse-url.
.gitignore First pass at wrapper for making requests. Crude and flat in structur… canonical repo now dakrone/clj-http
project.clj 0.1.3


The canonical repository for this project is now dakrone/clj-http.


A Clojure HTTP library wrapping the Apache HttpComponents client.


The main HTTP client functionality is provided by the clj-http.client namespace:

(require '[clj-http.client :as client])

The client supports simple get, head, put, post, and delete requests. Responses are returned as Ring-style response maps:

(client/get "")
=> {:status 200
    :headers {"date" "Sun, 01 Aug 2010 07:03:49 GMT"
              "cache-control" "private, max-age=0"
              "content-type" "text/html; charset=ISO-8859-1"
    :body "<!doctype html>..."}

More example requests:

(client/get "")

(client/get "" {:accept :json})

(client/post "" {:body byte-array})

(client/post "" {:body "string"})

(client/get "" {:basic-auth ["user" "pass"]})

(client/get "" {:query-params {"q" "foo, bar"}})

(client/get "" {:as :byte-array})

(client/post ""
  {:basic-auth ["user" "pass"]
   :body "{\"json\": \"input\"}"
   :headers {"X-Api-Version" "2"}
   :content-type :json
   :accept :json})

A more general response function is also available, which is useful as a primitive for building higher-level interfaces:

(defn api-action [method path & [opts]]
    (merge {:method method :url (str "" path)} opts)))

The client will throw exceptions on, well, exceptional status codes:

(client/get "")
=> Exception: 500

The client will also follow redirects on the appropriate 30* status codes.

The client transparently accepts and decompresses the gzip and deflate content encodings.


clj-http is available as a Maven artifact from Clojars:

  [[clj-http "0.1.3"] ...]


The design of clj-http is inspired by the Ring protocol for Clojure HTTP server applications.

The client in clj-http.core makes HTTP requests according to a given Ring request map and returns Ring response maps corresponding to the resulting HTTP response. The function clj-http.client/request uses Ring-style middleware to layer functionality over the core HTTP request/response implementation. Methods like clj-http.client/get are sugar over this clj-http.client/request function.


To run the tests:

$ lein deps
$ lein run -m
$ lein test


Released under the MIT License:

Something went wrong with that request. Please try again.