HTTP client/server for Clojure

HTTP Kit is a minimalist, efficient, Ring-compatible HTTP client/server for Clojure. It uses a event-driven architecture to support highly concurrent a/synchronous web applications. Feature a unified API for WebSocket and HTTP long polling/streaming

[http-kit "2.1.16"] ; Add to your project.clj.

Recent Blog Posts

HTTP Server documentation

(defn async-handler [ring-request]
  ;; unified API for WebSocket and HTTP long polling/streaming
  (with-channel ring-request channel    ; get the channel
    (if (websocket? channel)            ; if you want to distinguish them
      (on-receive channel (fn [data]     ; two way communication
                            (send! channel data)))
      (send! channel {:status 200
                      :headers {"Content-Type" "text/plain"}
                      :body    "Long polling?"}))))

(run-server async-handler {:port 8080}) ; Ring server

HTTP Client documentation

;; start concurrent requests, get promise, half the waiting time
(let [response1 (http-kit/get "http://http-kit.org/")
      response2 (http-kit/get "http://clojure.org/")]
  ;; Handle responses one-by-one, blocking as necessary
  ;; Other keys :headers :body :error :opts
  (println "response1's status: " (:status @response1))
  (println "response2's status: " (:status @response2)))

Ring Compliant

HTTP Kit is an (almost) drop-in replacement for the standard Ring Jetty adapter. So you can use it with all your current libraries (e.g. Compojure) and middleware.

High Performance

Using an event-driven architecture like Nginx, HTTP-kit is very, very fast. It comfortably handles tens of thousands of requests/sec on even midrange hardware. Here is another test about how it stacks up with others.

High Concurrency

It's not only fast, but efficient! Each connection costs nothing but a few kB of memory. RAM usage grows O(n) with connections.

Clean, Simple, Small

Written from the ground-up to be lean, the entire client/server is available as a single ~90kB JAR with zero dependencies and ~3k lines of (mostly Java) code.

Sync or Async

Synchronous is simple. Asynchronous is fast & flexible. With HTTP Kit you get the best of both with a simple API that lets you mix & match to best fit your use case.

WebSockets and Comet

With great out-the-box support for both WebSockets and efficient handling of long-held HTTP requests, realtime web applications are a breeze to write.

Open Source

HTTP Kit is on GitHub and is distributed under the Apache License Version 2.0. Want to make it better? Contributing is just a pull request away!