Created
December 17, 2013 17:45
-
-
Save tgk/8009355 to your computer and use it in GitHub Desktop.
Proposal for Riemann/Compojure routing integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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