Database Reference
In-Depth Information
There are a number of central concepts in Ring, which are described as follows:
F Handlers: These are the core of a web application. Handlers are Clojure functions
that take a map with information about the request and return a map with the
response. Each web application has one handler function.
F Middleware: This transforms incoming requests or outgoing responses.
Generally, middleware wraps an existing handler to provide extra functionality.
For instance, authentication can be handled through middleware. The project
Friend ( https://github.com/cemerick/friend ) does this. Middleware can
also handle requests for static resources, cookies, and many other things.
F Adapters: These connect Ring to web servers. Ring has an adapter for the Jetty
web server ( http://jetty.codehaus.org/jetty/ ) and this is what we use
in this recipe.
Ring's a good option to connect a web application to a web server, but it's a little too close to
the metal. You wouldn't want to write your web application to talk to Ring directly. Compojure
( https://github.com/weavejester/compojure/wiki ) steps into the gap. It provides
a simple DSL to deine routes and response functions and composes them into a single Ring
application handler function. It allows you to deine the type of HTTP request that each route
function can accept ( GET , POST , and so on) and what parameters each expect.
Here's how the preceding example breaks down into the components we just discussed:
F site-routes : This is composed of Compojure routes, which act as the Ring handler
F app : This is composed of the Ring handler function with some middleware
In our project.clj ile, we deine connect Ring to our handler function with this line:
:ring {:handler web-viz.web/app}
There's moreā€¦
F The Ring wiki at https://github.com/ring-clojure/ring/wiki has a lot of
useful information to get started and work with Ring.
F The Ring's API documentation at http://ring-clojure.github.com/ring/ is
also very helpful.
F However, if you want to get more complete information, you should take a look at the
Ring speciication, available at https://github.com/ring-clojure/ring/
blob/master/SPEC . It's really quite readable.
F The Compojure wiki at https://github.com/weavejester/compojure/wiki
has information on the many aspects of using Compojure.
F The Compojure API documentation at http://weavejester.github.com/
compojure/ is helpful too.
 
Search WWH ::




Custom Search