pedestal

lucian303 2021-06-08T01:50:33.023500Z

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?

2021-06-09T22:59:15.035200Z

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

2021-06-10T21:29:38.036300Z

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

souenzzo 2021-06-08T10:31:21.024Z

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

lucian303 2021-06-08T14:03:16.024400Z

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

souenzzo 2021-06-08T14:11:14.025700Z

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

2021-06-09T23:00:07.035500Z

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

souenzzo 2021-06-09T23:11:43.035700Z

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

souenzzo 2021-06-10T21:33:32.036500Z

@ddeaguiar any feedback about my usage?

2021-06-10T21:37:53.036700Z

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

souenzzo 2021-06-08T14:13:08.026700Z

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

souenzzo 2021-06-08T14:14:32.027800Z

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

lucian303 2021-06-08T16:51:18.028800Z

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

souenzzo 2021-06-08T20:00:43.029300Z

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