Skip to content

Instantly share code, notes, and snippets.

@Haifen
Last active August 29, 2015 14:03
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 Haifen/f87eb52e7961de52d60a to your computer and use it in GitHub Desktop.
Save Haifen/f87eb52e7961de52d60a to your computer and use it in GitHub Desktop.
Stupid crufty API
(ns noopy.core (:require [compojure.core :refer [ANY context GET routes]] [compojure.route :as route :refer [not-found]] [compojure.handler :as handler :refer [api site]] [hiccup.page :as hp :refer [html5]][clojure.java.io :as io]))
(def noop (api (routes
(ANY "/202/ihaveapublicip" {ip :remote-addr} (or (with-open [ipaf (io/writer "/home/robink/ipsofremotemachines.txt" :append true)] (binding [*out* ipaf] (print (str ip "\n")))) {:status 202 :headers {"Content-Type" "text/plain"} :body (str "IP address " ip " received and recorded, over and out.\n")}))
(ANY "/*" [] #(assoc {:status 501 :headers {"Content-Type" "text/html"}} :body (let [rts (html5 [:html [:head [:title "501"]] [:body [:h1 "501"] [:p "Sorry, we don't know what to do with that REST request yet. You requested " [:i (%1 :uri)] ". Here is your request map if it makes you feel better:"] [:code (pr-str %1)] ]] )] rts))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment