-
-
Notifications
You must be signed in to change notification settings - Fork 10
routes
In order to stub HTTP endpoints you must conform to the route schema. Here's an example:
{ "/something" {:status 200 :body "hello"}
"/something-else" {:status 201 } }
The key in this map is the request specification and the value is the response specification. The combination of key and value (i.e. request- and response specification) is called a route. You supply this route map to the with-routes! macro or the start!
function. For example:
(with-routes!
{ "/something" {:status 200 :body "hello"}
"/something-else" {:status 201 } }
(client/get ...))
As an alternative to explicitly declaring the route map (that consists of one to many routes) you can provide it from a function that takes a server
instance as a parameter. This is useful if you need access to some data from the server
in order to build up your routes. For example:
(fn [server]
(let [absolute-uri (str (:uri server) "/somewhere")]
{ "/somewhere" {:status 200 :body absolute-uri}}))
In this example we get the URI of the server (which may be autogenerated if using the macro for later use in our response specification. For example:
(with-routes!
(fn [server]
(let [absolute-uri (str (:uri server) "/somewhere")]
{ "/somewhere" {:status 200 :body absolute-uri}}))
(client/get ...))
The request specification (the key in the route map) can be created in three different ways:
-
Path only
This way