Adding simple middleware:
(defn wrap-upcase [app]
(defn with-upcase [app]
(fn [req]
(let [orig-resp (app req)]
(assoc orig-resp :body (.toUpperCase (:body orig-resp))))))
(def upcase-app (wrap-upcase app))
(def upcase-app (with-upcase app))
(run-jetty upcase-app {:port 8080})
Quick Start
First, pull in Ring's dependencies using Leiningen:
To see a live "Hello World" Ring app, run:
$ clj example/hello_world.clj
$ 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.
To see a more sophisticated Ring app, run:
$ clj example/wrapping.clj
$ clj src/ring/example/wrapping.clj
- If you request
http://localhost:8080/in your browser thering.handler.dumphandler will respond with an HTML page representing the request map that it received (see theSPECfor details on the request map). - If you request
http://localhost:8080/clojure.png, thering.middleware.filemiddleware will detect that there is aclojure.pngfile in the app'spublicdirectory 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 thering.middleware.stacktracemiddleware, which will in turn return a readable stacktrace as the HTML response.
Development
Ring is being actively developed; you can track its progress and contribute at the project's GitHub pageGitHub page and Google Group.
To run all the Ring unit tests:
$ clj test/ring/run.clj
$ lein test
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) 20092009-2010 Mark McGranaghan and released under an MIT license.
Clojure logo by Tom Hickey.
0 comments on commit
f2f4229