Skip to content

Instantly share code, notes, and snippets.

@fabioyamate
Created August 31, 2015 03:20
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 fabioyamate/7078c161fb7d7b235a4a to your computer and use it in GitHub Desktop.
Save fabioyamate/7078c161fb7d7b235a4a to your computer and use it in GitHub Desktop.
Stub HTTP server
(ns stubhttp.core
(:require [ring.adapter.jetty :as r]
[ring.middleware.json :as json]
[ring.util.response :as response]))
(def state (atom {}))
(defn register! [{uri "uri" {:strs [status headers body]} "response"}]
(swap! state assoc uri {:status status :headers headers :body body}))
;; POST /register
;; {"uri" "/api/echo" "response" {"status" 200 "headers" {} "body" "echo"}}
(defn handler [{:keys [request-method uri body] :as request}]
(if (and (= "/register" uri)
(= :post request-method))
(register! body)
(get @state uri (response/not-found "Not Found"))))
(defn -main [& args]
(r/run-jetty (json/wrap-json-body handler) {:port 3000}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment