duct-framework / duct

Server-side application framework for Clojure
MIT License
1.13k stars 51 forks source link

Handler component for compojure-api #38

Closed j0ni closed 8 years ago

j0ni commented 8 years ago

Thank you for duct.

I'm playing with compojure-api, and it looks like I need to apply the compojure.api.api/api fn here. Do you agree, or am I misunderstanding?

Would you accept a PR to modify the Handler component to accept a handler creation fn at runtime via a component config key?

weavejester commented 8 years ago

I'm afraid I don't know much about Compojure-API, as I'm not involved in the project, nor had reason to use the library. My guess is that you want to use the api function in the endpoints, since it seems to return a handler, and also seems to require knowledge of the routes. However, if you want to be certain, I'd ask the Compojure-API team directly.

j0ni commented 8 years ago

Thanks - I tried using the api function in the endpoints and it did work as far as I can see. I think for a use case where there are multiple middleware stacks (maybe some endpoints that serve pages, and others that serve APIs) that's OK.

I don't think it would be as trivial of a change as I initially thought either - there's a bunch of metadata that's added as part of the api function call which defines routes for swagger documentation and the swagger.json API definition. That would need to be handled too.

I've just started looking at Compojure-API - if I come up with a good solution I'll follow up here. Feel free to close this unless you want to keep it bookmarked for future work.

ku1ik commented 7 years ago

Hey @j0ni, have you found a good way to wrap all endpoints in a single api definition in the end? I encountered a similar problem.

j0ni commented 7 years ago

@sickill I haven't, though I haven't been in a situation where I cared that much since I wrote that.

I think if I had a leiningen task which reported the complete route map, a la rake routes in rails, I'd probably have everything I needed. One thing I like about Malcolm Sparks' bidi is that the routes are a simple data structure which it's easy to pretty print (or maybe print using something like ronda-routing-bidi, which I just found). But mostly I've just continued using compojure and compojure-api and either created a single routing map in one place, or lived with the (otherwise useful) isolation provided by duct.