1

Let's say I have User resource which has Address sub-resource (let's forget about why this is a resource instead of attribute). To get a user's address, I can do GET /users/{id}/address

Now I want to have an API which returns all the addresses regardless of their owners. I can do GET /addresses. This feels a little bit hacky.

Another option is to move the Address resource to the top level.

  • GET /user-addresses to get all addresses
  • GET /user-addresses/{user-id} to get a specific user's address
  • POST /user-addresses/{user-id} to create an address

Which one do you prefer? Have you seen similar patterns before? Thanks!

0

If you want to return all of the user's addresses, then I would map that to /users/addresses.

Moving address outside of the users resource in the endpoint tells me I'm getting more than just user addresses (ie. Store address). I'm assuming that's not what you're going for.

And anything like user-adresses sitting beside the user endpoint looks very messy, I'd avoid that.

  • The /users/addresses looks like a user resource and the id is addresses. So the path more or less conflicts with the /users/{id}. – wanghq Dec 17 '18 at 6:17
  • I disagree, but if you're actually worried about that then go with /addresses or /users/*/address – Adam Bates Dec 17 '18 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.