Last active
August 29, 2015 14:03
-
-
Save Haifen/f87eb52e7961de52d60a to your computer and use it in GitHub Desktop.
Stupid crufty API
This file contains 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 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