Choosing the Appropriate Route for a RESTful API

I am facing an issue with selecting the correct route for managing food photos in my application. I have records of food items along with their associated images. To retrieve all the images of a specific food item, I utilize the following endpoint:

GET /food/{id}/images

For uploading a new image to a particular food item, I employ this command:

POST /food/{id}/images

The challenge arises when I attempt to remove a photo. Since users can submit multiple images for the same food item, I cannot simply use:

DELETE /food/{id}/images

I have two potential solutions for this dilemma:

DELETE /food/{food_id}/images/{image_id}
DELETE /images/{id}

The first option maintains consistency with my photo retrieval structure but introduces redundancy since each image holds a unique identifier, making the food ID unnecessary. The second option appears cleaner, yet it lacks uniformity since image creation uses the /food/ prefix while deletion does not. Which routing strategy do you recommend?

Incorporating DELETE /food/{food_id}/images/{image_id} has its own advantages. This approach adds context to your deletion operation by explicitly tying images to their respective food items, which might help in scenarios where you will need to validate if the request has permissions for a specific food item. It can also improve the API’s readability for consumers who will understand directly which food item the image belongs to, helping maintain traceability and integrity of your data.

I think using DELETE /images/{id} is a smart move. It’s simpler & more effient because ur dealing w/ unique image ids anyway. Keeping things simple is often the way to go. Plus, someday you might want to manage images independently. Go for clarity over uniformity!