By current standards HTML forms can only call the GET and POST methods, but in a RESTful web service you may want to implement PUT and DELETE methods for your resources. Compojure provides a work-around that allows you to implement REST's uniform interface once for browsers and less restricted clients with no explicit server-side handling. The client should send a parameter named "_method" with the value of the method you really want called. You can add a hidden field to HTML forms for this purpose, and other clients can simply call PUT or DELETE without the parameter. Compojure's handler infrastructure will replace the actual method with the "_method" parameter's value before calling your handlers.

It is possible to modify the response through the response object, but this is almost never necessary. Instead, Compojure takes a functional approach, constructing the HTTP response from the return value of the resource.

In the previous examples, you can see how returning a string adds to the response body. Other standard Clojure types modify the response in different ways:

java.lang.String - adds to the response body

java.lang.Number - changes the status code

Clojure map - updates (merges) the response Map

Clojure seq - lazily adds to the response body

java.io.File - streams the file to the response body

java.io.InputStream - reads from the stream and adds to the response body

java.net.URL - streams the resource of the URL to the response body

java.servlet.http.Cookie - adds the cookie to the HTTP headers

These modifications can be chained together using a standard Clojure vector:

The HTML library provides a way of defining HTML or XML through a tree of vectors.

(html [:p [:em "Hello World"]])

<p><em>Hello World</em></p>

The tag name is taken from the first item of the vector, and can be a string, symbol or keyword. You can optionally specify attributes for the tag by providing a hash map as the second item of the vector: