Home > other >  Restful endpoint for resource
Restful endpoint for resource

Time:09-29

If I have user/{id}/resource and I want to download my specific resource, how would I go about correctly naming the endpoint?

user/{id}/resource/download doesnt follow the restful design pattern, and having user/{id}/resourcedownload then doesn't describe the correct resource?

CodePudding user response:

I think you're a little confused at how API naming schemas should be working. When you specify an ID in the URL, you are requesting one resource. The resource of that ID. To make this make sense, since I do not know your database structure, we will use an example with movies.

If you wanted to get a list of all movies, you should use something like /api/movies. If you wanted a specific movie, you'd use something like /api/movies/{id}.

The same would hold true for other resources. If you wanted a list of all the actors, you'd use something like /api/actors. If you wanted a specific actor, you'd use something like /api/actors/{id}. If you wanted a list of all movies an actor is in, you'd use something like /api/actors/{id}/movies, or if you wanted a specific movie an actor was in: /api/actors/{actorId}/movies/{movieId} or just simply /api/movies/{id}.

Keep in mind, this is an over simplification to get you an idea of naming conventions. If a real API, you might have other information, such as pagination and offset, etc...

  • Related