How to separate endpoints out in to a folder structure in iity? #147
Replies: 2 comments
-
Curious how you ended up doing this as I have a similar issue. The Cloudflare worker I am working on has tons of endpoints too. What we are doing for now, as we cant figure out how to structure is to just make each endpoint it's own route and just group them together in the code, which is obviously not ideal, as you end up with a huge amount of routes. Wondering also, how to create a sort of folder like structure. |
Beta Was this translation helpful? Give feedback.
-
So I usually group by function, as it appears you've done... as in my root router just registers child routers (each in separate files/folders). If you were to go further and split out files to individual handlers, your example is perfectly fine. I mean, this is probably a bit silly to suggest, but if you're just visiting the endpoint (via a GET in the browser), your route+handler is on POST, and thus won't catch... hope that's the only issue here, because otherwise it looks fine! Now, if that's really a POST call that's missing, I'd have to dig deeper... but your setup looks similar to many of mine! |
Beta Was this translation helpful? Give feedback.
-
Hello,
I would like to use itty to build an API to be deployed on Cloudflare Workers. It's quite a big API, with lots of endpoints. I'm trying to find a way where I can set up folders for /posts /comments /reviews etc.. and then within each of those folders have the specific endpoint, such as /posts/fetch-all-posts and posts/delete-post etc..
I've set it up like this at the moment:
In the postsRouter I've tried to import the 'add-post' endpoint, but I can't get it to 'find it' If I visit:
http://0.0.0.0:8787/listings/get-all-listings I get the correct response: 'Get all listings endpoint', but if I visit http://0.0.0.0:8787/listings/add-listings it says 'Not found.'
Can anyone see what I'm doing wrong, please? My handleAddPost is just a simple:
Many thanks for any help! Cheers, Matt
Beta Was this translation helpful? Give feedback.
All reactions