Top Related Projects
Quick Overview
Ring is a Clojure web application library that provides a simple and consistent API for building web applications. It abstracts away the details of the underlying HTTP server, allowing developers to focus on writing application logic rather than dealing with the complexities of the web server.
Pros
- Simplicity: Ring provides a straightforward and easy-to-use API for building web applications, making it accessible to developers of all skill levels.
- Flexibility: Ring is designed to be a lightweight and modular library, allowing developers to choose the components they need and build their applications in a modular fashion.
- Portability: Ring applications can be deployed on a variety of web servers, including Jetty, Tomcat, and Nginx, making it a versatile choice for web development.
- Community Support: Ring has a large and active community of developers, with a wealth of resources, libraries, and tools available to help developers build their applications.
Cons
- Limited Functionality: While Ring provides a solid foundation for building web applications, it may lack some of the more advanced features and functionality found in other web frameworks.
- Steep Learning Curve: For developers new to Clojure or functional programming, the concepts and syntax used in Ring may take some time to get used to.
- Dependency Management: Managing dependencies and ensuring compatibility between different Ring-based libraries can be a challenge, especially for larger projects.
- Performance: While Ring is generally fast and efficient, it may not be the best choice for building highly-performant, high-traffic web applications.
Code Examples
Here are a few examples of how to use Ring to build a simple web application:
(ns my-app.core
(:require [ring.adapter.jetty :refer [run-jetty]]
[ring.middleware.params :refer [wrap-params]]
[ring.util.response :refer [response]]))
(defn hello-handler [request]
(response "Hello, World!"))
(def app
(-> hello-handler
(wrap-params)))
(defn -main []
(run-jetty app {:port 3000}))
This example sets up a simple Ring application that responds with "Hello, World!" when the root URL is accessed.
(ns my-app.core
(:require [ring.adapter.jetty :refer [run-jetty]]
[ring.middleware.params :refer [wrap-params]]
[ring.util.response :refer [response]]))
(defn greet-handler [request]
(let [name (get-in request [:params "name"])]
(response (str "Hello, " name "!"))))
(def app
(-> greet-handler
(wrap-params)))
(defn -main []
(run-jetty app {:port 3000}))
This example demonstrates how to handle query parameters in a Ring application. When the /greet?name=John
URL is accessed, the application will respond with "Hello, John!".
(ns my-app.core
(:require [ring.adapter.jetty :refer [run-jetty]]
[ring.middleware.params :refer [wrap-params]]
[ring.util.response :refer [response]]))
(defn todo-handler [request]
(let [todo (get-in request [:params "todo"])]
(response (str "Added todo: " todo))))
(def app
(-> todo-handler
(wrap-params)))
(defn -main []
(run-jetty app {:port 3000}))
This example shows how to handle form data in a Ring application. When the /todo
URL is accessed with a todo
parameter, the application will respond with a message indicating the added todo item.
Getting Started
To get started with Ring, you'll need to have Clojure and a build tool like Leiningen or Boot installed. Here's a quick example of how to set up a new Ring project using Leiningen:
- Create a new Leiningen project:
lein new app my-app
- Add the Ring dependency to your
project.clj
file:
(defproject my-app "0.1.0-
Competitor Comparisons
The Pedestal Server-side Libraries
Pros of Pedestal
- Pedestal provides a more opinionated and structured approach to building web applications, with a focus on modularity and extensibility.
- Pedestal includes built-in support for features like routing, middleware, and dependency injection, which can simplify the development process.
- Pedestal's emphasis on separation of concerns and testability can make it easier to maintain and scale complex web applications.
Cons of Pedestal
- Pedestal has a steeper learning curve compared to Ring, as it introduces more concepts and abstractions.
- Pedestal's opinionated nature may not align with the preferences of all developers, who may prefer a more flexible and minimalistic approach.
- The Pedestal ecosystem is generally smaller and less mature than the Ring ecosystem, which may mean fewer third-party libraries and resources available.
Code Comparison
Here's a brief comparison of how to set up a simple web server using Ring and Pedestal:
Ring:
(require '[ring.adapter.jetty :refer [run-jetty]])
(defn handler [request]
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Hello, World!"})
(run-jetty handler {:port 8080})
Pedestal:
(require '[io.pedestal.http :as http])
(defn hello-world [request]
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Hello, World!"})
(def service-map
{::http/routes #{["/hello" :get `hello-world]}
::http/type :jetty
::http/port 8080})
(http/start (http/create-server service-map))
A concise routing library for Ring/Clojure
Pros of Compojure
- Compojure provides a more concise and expressive syntax for defining routes, making it easier to organize and manage complex web applications.
- Compojure's routing system is more flexible and powerful, allowing for advanced features like route parameters, middleware, and nested routes.
- Compojure integrates well with other Clojure libraries and frameworks, making it a popular choice for building Clojure-based web applications.
Cons of Compojure
- Compojure has a steeper learning curve compared to Ring, as it introduces its own routing DSL and conventions.
- Compojure's focus on routing may make it less suitable for building more complex, non-web-based applications, where Ring's more generic approach may be more appropriate.
- Compojure's development and maintenance may be less active compared to the larger and more widely used Ring project.
Code Comparison
Ring:
(defn handler [request]
{:status 200
:headers {"Content-Type" "text/html"}
:body "Hello, World!"})
(def app
(-> handler
(wrap-params)
(wrap-session)
(wrap-defaults site-defaults)))
Compojure:
(defroutes app-routes
(GET "/" [] "Hello, World!")
(POST "/submit" request
(println (:params request))
{:status 302, :headers {"Location" "/"}})
(route/not-found "Page not found"))
(def app
(-> app-routes
(wrap-params)
(wrap-session)
(wrap-defaults site-defaults)))
Simple, high-performance event-driven HTTP client+server for Clojure
Pros of http-kit/http-kit
- Lightweight and fast, making it suitable for high-performance web applications.
- Supports WebSockets, which allows for real-time communication between the client and server.
- Provides a simple and easy-to-use API for handling HTTP requests and responses.
Cons of http-kit/http-kit
- Lacks some of the features and flexibility provided by Ring, such as middleware and a more extensive ecosystem of libraries.
- May require more manual configuration and setup compared to Ring, which has a more established and opinionated approach.
- Has a smaller community and ecosystem compared to Ring, which may limit the availability of third-party libraries and resources.
Code Comparison
Here's a brief comparison of how to create a simple HTTP server using Ring and http-kit:
Ring:
(require '[ring.adapter.jetty :refer [run-jetty]])
(require '[ring.middleware.params :refer [wrap-params]])
(defn handler [request]
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Hello, World!"})
(def app
(-> handler
(wrap-params)))
(run-jetty app {:port 3000})
http-kit:
(require '[org.httpkit.server :refer [run-server]])
(defn handler [req]
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Hello, World!"})
(run-server handler {:port 3000})
As you can see, the http-kit version is more concise and requires less boilerplate code to set up a simple HTTP server.
A fast data-driven routing library for Clojure/Script
Pros of reitit
- Routing Flexibility: reitit provides a more flexible and extensible routing system compared to Ring, allowing for dynamic route definitions and advanced features like path parameters and route hierarchy.
- Performance: reitit is designed for performance, with a focus on fast route matching and efficient request handling.
- Ecosystem Integration: reitit integrates well with other Clojure/ClojureScript libraries and frameworks, making it a versatile choice for building web applications.
Cons of reitit
- Learning Curve: reitit has a steeper learning curve compared to the more established Ring library, which may be a consideration for developers new to the Clojure ecosystem.
- Dependency Management: reitit has a larger set of dependencies compared to Ring, which may be a concern for some projects that prioritize minimizing the dependency footprint.
Code Comparison
Ring (Clojure):
(defn handler [request]
{:status 200
:headers {"Content-Type" "text/plain"}
:body "Hello, World!"})
(def app
(ring/wrap-defaults handler site-defaults))
reitit (Clojure):
(def app
(reitit/ring-handler
(reitit/router
[["/" {:get {:handler (fn [_] {:status 200, :body "Hello, World!"})}]]),
{:data {:middleware [wrap-params
wrap-keyword-params
wrap-json-response]}}))
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Ring 
Ring is a Clojure web applications library inspired by Python's WSGI and Ruby's Rack. By abstracting the details of HTTP into a simple, unified API, Ring allows web applications to be constructed of modular components that can be shared among a variety of applications, web servers, and web frameworks.
The SPEC.md file at the root of this distribution provides a complete description of the Ring interface. The Wiki contains more in-depth documentation on how to use Ring.
Libraries
ring/ring
- meta-package containing all relevant dependenciesring/ring-core
- core functions and middleware for Ring handlers, requests and responsesorg.ring-clojure/ring-core-protocols
- contains only the protocols necessary for building Ring responsesorg.ring-clojure/ring-websocket-protocols
- contains only the protocols necessary for WebSocketsring/ring-devel
- functions for developing and debugging Ring applicationsring/ring-servlet
- construct legacy Java Servlets (⤠4.0) from Ring handlersorg.ring-clojure/ring-jakarta-servlet
construct Jakarta Servlets (⥠5.0) from Ring handlersring/ring-jetty-adapter
- a Ring adapter that uses an embedded Jetty web server
Installation
To include one of the above libraries, for instance ring-core
, add
the following dependency to your deps.edn
file:
ring/ring-core {:mvn/version "1.14.1"}
Or to your Leiningen project file:
[ring/ring-core "1.14.1"]
Documentation
Contributing
Please read CONTRIBUTING.md before submitting a pull request.
Thanks
This project borrows heavily from Ruby's Rack and Python's WSGI; thanks to those communities for their work. Thanks also go to the many individuals who have contributed to Ring's code and documentation over the years.
License
Copyright © 2009-2025 Mark McGranaghan, James Reeves & contributors.
Released under the MIT license.
Top Related Projects
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot