Skip to content

Instantly share code, notes, and snippets.

@tgk
Created December 17, 2013 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgk/8009355 to your computer and use it in GitHub Desktop.
Save tgk/8009355 to your computer and use it in GitHub Desktop.
Proposal for Riemann/Compojure routing integration
(ns compojure-augmented.core
(:require [compojure.core]))
(def bare
(compojure.core/GET
"/foo/:bar" [bar]
{:status 200
:body (str "Hello " bar)}))
(bare
{:request-method :get
:uri "/foo/test"})
;; => {:status 200, :headers {}, :body "Hello test"}
(defmacro augmented-GET
[path args & body]
`(let [handler# (compojure.core/GET ~path ~args ~@body)]
(fn [request#]
(when-let [response# (handler# request#)]
(assoc response# :path ~path)))))
(def augmented
(augmented-GET
"/foo/:bar" [bar]
{:status 200
:body (str "Hiya " bar)}))
(augmented
{:request-method :get
:uri "/foo/fest"})
;; => {:path "/foo/:bar", :status 200, :headers {}, :body "Hiya fest"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment