Skip to content

Instantly share code, notes, and snippets.

@jstaffans
Created August 20, 2017 16:09
Show Gist options
  • Save jstaffans/bf087bc84708ebc0faf8a1941a79e04e to your computer and use it in GitHub Desktop.
Save jstaffans/bf087bc84708ebc0faf8a1941a79e04e to your computer and use it in GitHub Desktop.
Mock an API by using a well-structured directory tree
(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