github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

mmcgrana / ring

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 145
    • 8
  • Source
  • Commits
  • Network (8)
  • Issues (0)
  • Downloads (2)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (2)
    • master ✓
    • sessions
  • Tags (1)
    • 0.1.0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Clojure web application library: abstracts HTTP to allow modular and concise webapps — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

:configurator and :join? arguments to run-jetty. 
rnewman (author)
Sat Feb 06 21:57:52 -0800 2010
commit  3e71902121899c798b9298473b0f322231283192
tree    779b28c8bcfc079e88f324926a03e841f971381c
parent  f282a7f74844f535938dc96f7007bf33e0e5cc2d
ring /
name age
history
message
file .gitignore Sun Jan 24 12:56:22 -0800 2010 Add .gitignore [mmcgrana]
file LICENSE Mon Jan 12 09:42:31 -0800 2009 Initial import from http://github.com/mmcgrana/... [mmcgrana]
file README.markdown Sun Jan 17 10:51:05 -0800 2010 Leiningen dependency management. [mmcgrana]
file SPEC Sun Sep 06 16:32:07 -0700 2009 Update readme and spec to reflect 0.1 [mmcgrana]
directory example/ Fri Jan 22 16:28:51 -0800 2010 Move examples out of , so that Lein does not au... [rnewman]
file project.clj Tue Jan 26 17:45:57 -0800 2010 Depend on clojure-contrib 1.1.0 final. [mmcgrana]
directory src/ Sat Feb 06 21:57:52 -0800 2010 :configurator and :join? arguments to run-jetty. [rnewman]
directory test/ Tue Jan 26 17:43:38 -0800 2010 Port tests to clojure.test. [mmcgrana]
README.markdown

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 file at the root of this distribution for provides a complete description of the Ring interface.

Examples

A Ring handler:

(use 'ring.adapter.jetty)

(defn app [req]
  {:status  200
   :headers {"Content-Type" "text/html"}
   :body    "Hello World from Ring"})

(run-jetty app {:port 8080})

Adding simple middleware:

(defn with-upcase [app]
  (fn [req]
    (let [orig-resp (app req)]
      (assoc orig-resp :body (.toUpperCase (:body orig-resp))))))

(def upcase-app (with-upcase app))

(run-jetty upcase-app {:port 8080})

Quick Start

First, pull in Ring's dependencies using Leiningen:

$ lein deps

To see a live "Hello World" Ring app, run:

$ clj src/ring/example/hello_world.clj

Now visit http://localhost:8080/ in your browser; the Ring app will respond to your request with a simple HTML page indicating the time of day.

Note that your clj script needs to add the src directory and the jars in lib to your classpath.

To see a more sophisticated Ring app, run:

$ clj src/ring/example/wrapping.clj
  • If you request http://localhost:8080/ in your browser the ring.handler.dump handler will respond with an HTML page representing the request map that it received (see the SPEC for details on the request map).
  • If you request http://localhost:8080/clojure.png, the ring.middleware.file middleware will detect that there is a clojure.png file in the app's public directory and return that image as a response.
  • If you request http://localhost:8080/error, the app will produce an error that will be caught by the ring.middleware.stacktrace middleware, which will in turn return a readable stacktrace as the HTML response.

Included Libs

  • ring.adapter.jetty: Adapter for the Jetty webserver.
  • ring.adapter.httpcore: Adapter for the Apache HttpCore webserver.
  • ring.middleware.file: Middleware that serves static files out of a public directory.
  • ring.middleware.file-info: Middleware that augments response headers with info about File responses.
  • ring.middleware.lint: Linter for the Ring interface, ensures compliance with the Ring spec.
  • ring.middleware.reload: Middleware to automatically reload selected libs before each requests, minimizing server restarts.
  • ring.middleware.stacktrace: Middleware that catches exceptions and displays readable stacktraces for debugging.
  • ring.middleware.static: Middleware that serves static files with specified prefixes out of a public directory.
  • ring.handler.dump: Handler that dumps request maps as HTML responses for debugging.
  • ring.util.servlet: Utilities for interfacing with Java Servlets.
  • ring.example.*: Various example Ring apps.

Development

Ring is being actively developed; you can track its progress and contribute at the project's GitHub page.

To run all the Ring unit tests:

$ clj test/ring/run.clj

Thanks

This project borrows heavily from Ruby's Rack and Python's WSGI, and I thank the communities developing and supporting those projects.

License

Copyright (c) 2009 Mark McGranaghan and released under an MIT license.

Clojure logo by Tom Hickey.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server