Created
August 31, 2015 03:20
-
-
Save fabioyamate/7078c161fb7d7b235a4a to your computer and use it in GitHub Desktop.
Stub HTTP server
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 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