With Compojure, is there a way to redirect to one of the defined routes, other than having to format the request URL?
For example, in the following simplified defroutes
declaration:
(defroutes app-routes
; ...
(GET "/something-that-may-redirect" [query-param]
; parse `query-param` into `arg1` and `arg2` and:
(ring.util.response/redirect (format "/another-route?param1=%s¶m2=%s" arg1 arg2))
(GET "/another-route" [param1 param2] ...)
; ...
Here, I have to format the URL to redirect to (and normally also deal with escaping), in order for this URL to be later parsed by Compojure itself and extract back the values for param1
and param2
.
So the question is if there is an approach to redirect and let Compojure to format the request URL, knowing that it already has information about the arguments? Something as simple as:
(redirect "/another-route" arg1 arg2)
which would format a URL itlsef into:
"/another-route?param1=[value of arg1]¶m2=[value of arg2]"
P.S. The idea itself it not new certainly. Some other Web frameworks have similar features - for example, with Python's Flask web framework one can use url_for to create a well-formatted and escaped URL out of base path and query parameter values:
# for example, in Python's Flask framework
url_for('route-name', param1='value1', param2='value2')