I have an app that generates keys based for specific datastores. If there are 7 such routes and 5 apps, there would be a total of 35 routes in my event.clj (or, if split out, 7/file in 5 files). I would like to do the following dynamically:
(defnested "/:app-name"
(defpage "/generate/event" {:keys [app-name event-name time] :as key-map}
(response/json
{:key (key-model/build-key :event key-map)}))
(defpage "/generate/event/unread" {:keys [app-name event-name] :as key-map}
(response/json
{:key (key-model/build-key :unread-for-event key-map)}))
)
That way I can write each route once and then pass around the app-name (instead of passing it in the query params, which works but isn't very RESTful.
BONUS
How can I dynamically call a namespace so that key-model/build-key
becomes a call to redis-model/build-key
or riak-model/build-key
based on the app name?