News for hackers. Stuff that matters.
Re:Ask HN: Nested Resources in REST/HTTP API URLs? by Vanit on Thursday August 18, 2022 @11:31PM (#32517349)
Yep this is it. If you nest IDs you just end up burdening all consumers with having to mimic your hierarchical structure when they don't need to.
Re:Ask HN: Nested Resources in REST/HTTP API URLs? by Twisol on Friday August 19, 2022 @12:53AM (#32517659)
It's worth noting that hierarchy itself isn't the problem, only hierarchy that isn't necessary for identifying a resource. If you happen to start comments on every post from 0 -- something like a (post_id, comment_id) primary key constraint on your comments table -- then it's natural to have a `/posts/1/comments/2` structure for your URLs. Under this data model, if you just had `/comments/2`, you wouldn't know enough to actually identify the comment -- just that it's the second comment on some post.

Whether it's a good idea to use this kind of composite key is a separate question, though.