Created
August 20, 2017 16:09
-
-
Save jstaffans/bf087bc84708ebc0faf8a1941a79e04e to your computer and use it in GitHub Desktop.
Mock an API by using a well-structured directory tree
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
(defn mock-api-response | |
[prefix-path uri] | |
(let [resource-path (format "%s/%s/index.json" prefix-path uri)] | |
{:headers {"Content-Type" "application/json" | |
"Access-Control-Allow-Origin" "*"} | |
:body (slurp (io/resource resource-path))})) | |
(defroutes routes | |
(GET "/mock/:uri{[\\/\w\d]+}" [uri] | |
(mock-api-response "mock_api" uri))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment