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
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
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
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ā¦
useful information to get started and work with Ring.
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.
has information on the many aspects of using Compojure.
compojure/
is helpful too.