Skip to content

Compojureλ︎

To make our webapp more useful we will add more functionality, which will require more routes.

Compojure is a library that works with Ring to manage

  • routing - running different code depending on the URL path received
  • http method switching - running different code based on the HTTP method (GET, POST, PUT, DELETE)

Compojure also has convenience functions that make ring responses easier to generate.

In this section we will update our project to use Compojure.

Ring - Compojure routes

Leiningen Templatesλ︎

Templates can be used to create a project with a given set of dependencies as well as Clojure code.

There is a compojure template that gives you a basic running web application. To use this template to create a new project use the following command, substituting your own project-name

lein new compojure project-name

This project contains ring and compojure. The dependency for ring is ring/site-defaults which includes some sensible default settings for your application, eg security settings such as anti-forgery.

See the definition of ring/site-defaults for further information.

Resourcesλ︎