Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active September 18, 2017 11:45
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 borkdude/7ce01912bd8af1dfbc868f7ba82da46b to your computer and use it in GitHub Desktop.
Save borkdude/7ce01912bd8af1dfbc868f7ba82da46b to your computer and use it in GitHub Desktop.
Yada no 404
(require '[yada.yada :as y])
(require '[bidi.vhosts :refer [vhosts-model]])
(require '[clj-http.client :as client])
(defmacro with-server
"Runs resource in server and defines url for use in body"
[resource & body]
`(let [resource# ~resource
vmodel# (vhosts-model [:* ["/api/foo" resource#]])
listener# (y/listener vmodel#)
port# (:port listener#)
close# (:close listener#)
~'url (str "http://localhost:" port# "/api/foo")]
~@body
(close#)))
(comment
(with-server (y/resource
{:methods {:post {:produces "application/json"
:response (fn [ctx] nil)}}})
(println (:status (client/post url))))) ;; 200??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment