Created
October 12, 2016 23:51
-
-
Save rbxbx/84e94580996d07ff42d751ac1e03da41 to your computer and use it in GitHub Desktop.
test url helper crap
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
(defn server-port | |
"Returns the port of a running Jetty server. (Implementation note: | |
connectors are the mechanism through which Jetty accepts network | |
connections for various protocols.)" | |
[server] | |
(let [connectors (.getConnectors server)] | |
(assert (= 1 (count connectors))) | |
(.getLocalPort (first connectors)))) | |
(defn url-helper | |
"Returns a URL string from a variable number of arguments." | |
[& paths] | |
(apply str "http://localhost:" paths)) | |
(defn construct-path | |
[path webserver] | |
(url-helper (server-port webserver) path)) | |
(defn request-map | |
[form-params token & [opts]] | |
(merge | |
{:form-params form-params | |
:headers {"Authorization" (str "Bearer " token)} | |
:content-type :json | |
:throw-exceptions false | |
:throw-entire-message? false} | |
opts)) | |
(defn POST | |
[path params token server] | |
(http/post (construct-path path server) | |
(request-map params token))) | |
(defn PUT | |
[path params token server] | |
(http/put (construct-path path server) | |
(request-map params token))) | |
(defn GET | |
[path token server] | |
(http/get (construct-path path server) | |
(-> (request-map {} token) | |
(dissoc :form-params)))) | |
(defn DELETE | |
[path token server] | |
(http/delete (construct-path path server) | |
(-> (request-map {} token) | |
(dissoc :form-params)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment