Posted on January 5, 2017
Ring provides a common and useful abstaction that builds up a web application like lego bricks. Most web application written in Clojure uses Ring.
Adapter adapts existing JVM web server libraries to be
compatible with the Ring specification. Adapter primary job
is to accept
requests and convert it into
Ring requests and pass it to
handler will return a
Ring response and
adapter convert it to
Handlers accept a
request and output
Ring response. Handlers are simply
Clojure funtions, they take a single argument the
Ring request and
return single value
Ring response, computing that
function is upto that function.
Ring response has 3 parts * Status:
Http status code which is integer.
* Body: Either string, file * Headers: Map of string
Middleware are functions that takes handler and return a
different handler, they also takes optional argument to
configure them, if needed those option needs to be in end.
The most common function to
middlerware is to transform the
request before it passed to
handler or it is passed to
Compojure takes cares of two things
- Routing- Running different code based on the URL
- Http Method Switchng -Running different code based on
Below is sample code for how Ring and Compojure works!