I am designing a JAX-RS REST Server using Clojure and RESTEasy.
It is my understanding that applications written in Lisp-family languages are, more than those in "traditional" imperative languages, built up as "domain-specific languages". The application is designed from the bottom-up as more and more "refined" functions until, at the "top" level, the application becomes a series of function calls to very high-level functions.
I am trying to do this for my REST server, starting with the resource classes that service URL requests (GET, POST, PUT, DELETE).
Here is my first resource:
(ns com.example.server.resources.buildtime
(:import [javax.ws.rs CookieParam GET Produces Path]
[javax.ws.rs.core Context Cookie NewCookie Response UriInfo]
[org.jboss.resteasy.annotations.providers.jaxb Formatted]))
(definterface BuildTime
(getBuildTime [^javax.ws.rs.core.UriInfo info
^javax.ws.rs.core.Cookie security-cookie]))
(deftype
^{Formatted true}
BuildTimeResource []
BuildTime
(^{GET true
Path "/buildtime"
Produces ["application/json"]}
getBuildTime
[this info security-cookie]
(.. (Response/ok "20111009") build)))
This resource returns the server build time as a String (enclosed in a JSON package) when called at the URL "/buildtime" with the GET http method.
I will be writing many more of the these resource classes and enclosed methods (most classes will have more than one method), each with a definterface and a deftype. This seems like a perfect use for macros.
I am soliciting suggestions for how this might be done as a DSL. How does one go about thinking in terms of DSLs?