1

I'm designing an API for a website where users can share images and all other users can see these images. The current idea is to have a path /user/name/images/xyz to GET a user's image and then a path images/abc to GET any public image "abc." I'm worried that there is a design flaw if I'm separating image retrieval across multiple endpoints. What's the most proper way to design this?

2
  • Where does the "xyz" or "abc" come from? Is that an id that will be generated by your system or is it something that is controlled by a user? Commented Feb 10, 2020 at 17:51
  • Sorry that's meant to be an id, possibly a hashcode or something uniquely identifying of the image. Commented Feb 10, 2020 at 19:48

1 Answer 1

1

The URL /users/NAME/images/XYZ infers that image XYZ is a subresource of user NAME. This also means that /users/bob/images/XYZ and /users/edna/images/XYZ are different images even though they share the same name (XYZ). If no such semantic relationship exists, or no two images should have the same name, then /images/XYZ is preferable.

Now imagine what happens if the client requests /users/NAME/images. Should they get a list of images filtered by that user? What happens if the client requests /images?

The answers to these questions can help drive your URL structure.

1
  • I think images should not strictly be a subresource of user/NAME. I guess that I'm asking whether it's okay design to have a /images/XYZ for any image and /user/NAME/images/ to get the collection of user images? Or does this overlapping "resource" indicate a flaw in design. Commented Feb 11, 2020 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.