i have a routes namespace where i define some routes (def routes #{["/Team" :get (conj api-interceptors
entities/team-stubs)]})` and an entities namespace where i implement that route. how can i use the url-for-routes
in the entities namespace to include links to other endpoints without causing a circular reference? (def url-for (route/url-for-routes routes/app-routes))
it seems like this would be the most common usage but it results in circular references and thus cannot be done ... what can i do short of putting the entire app in one namespace? is there a solution to this common issue?
@lucian303 have you tried routes/url-for
? If so, why doesn’t it meet your needs? It only requires a route name (https://github.com/pedestal/pedestal/blob/d20065013abf5d3793ae5301e18a2398707fa2a9/samples/http2/src/hp/service.clj#L13).
Ok. I’ll look into rewording that example to avoid confusion.
I have this issue too @lucian303 You can use route/url-for from inside requests But it's not a final solution
u mean that function is available in the request map? @souenzzo
Not exactly inside the request map
But there is the route/*url-for*
available, if you are inside a interceptor/handler called after the standard route interceptor
https://github.com/pedestal/pedestal/blob/master/route/src/io/pedestal/http/route.clj#L374
@souenzzo, what use case requires this? Why isn’t routes/url-for
sufficient?
- we had a handler that use route/url-for
to generate and send a email to the user
- we changed our approach. moved this handler into a kafka batch processing, providing the same parameters that the http-handler used to have (query-params etc)
- the handler stopped to work because it uses route/url-for and it's not available
- once we pretend to move many endpoints into kafka, we choose to provide the route/*url-for*
inside the kafka processing context.
@ddeaguiar any feedback about my usage?
I think that’s fine. route/url-for
was intended to be used within request execution.
I don't know/understand why it's not a value in the context/request, or at least a public var.
I use (with-bindings {#'route/*url-for* my-custom-url-for}
in some places in my code
pedestal.route is an awesome lib, but without docs is really hard to use also, there is some design deicisions that i can't understand
i c. i'll try that. i was already trying all kinds of require hacks and such so any solution at this point, no matter how hacky, is most welcome
@lucian303 you can use promise/deliver to avoid circular deps