Fork me on GitHub
#pedestal
<
2021-06-08
>
lucian30301:06:33

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?

ddeaguiar22:06:15

@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).

lucian30318:06:44

thank you @ddeaguiar that's what i was looking for. i hadn't tried it because i didn't understand that part of the documentation and i thought the reference to url-for was the url-for created using url-for-routes in the example code at http://pedestal.io/guides/defining-routes

ddeaguiar21:06:38

Ok. I’ll look into rewording that example to avoid confusion.

souenzzo10:06:21

I have this issue too @lucian303 You can use route/url-for from inside requests But it's not a final solution

lucian30314:06:16

u mean that function is available in the request map? @souenzzo

souenzzo14:06:14

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

ddeaguiar23:06:07

@souenzzo, what use case requires this? Why isn’t routes/url-for sufficient?

souenzzo23:06:43

- 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.

souenzzo21:06:32

@ddeaguiar any feedback about my usage?

ddeaguiar21:06:53

I think that’s fine. route/url-for was intended to be used within request execution.

souenzzo14:06:08

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

souenzzo14:06:32

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

lucian30316:06:18

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

souenzzo20:06:43

@lucian303 you can use promise/deliver to avoid circular deps