I am designing a REST API that has to deal with users and two video uploads associated to each user. So far, I've come up with two different approaches of modeling this:
- Video as part of a user resource.
- Video as a subresource of a user resource.
Each approach has its (philosophical) advantages and problems: To explain in more detail, the model for my users resource kinda looks like this:
{
"id": Number, // user id
"cat_video_upload_date": Date, // initially unset, date of cat video upload
"dog_video_upload_date": Date, // initially unset, date of dog video upload
}
Going for approach 1, I have
PATCH /users/{id}
to update a user resource with a video via multipart uploadGET /users/{id}/{file}
wherefile
can be "cat.mp4" or "dog.mp4"
While the PATCH looks fine wrt REST, I feel that GET /users/{id}/{file}
is "wrong" when it comes to sticking with the true nature of a RESTful API. It should probably rather be GET /users/{id}#{file}
, treating the file as a secondary resource as highlighed by this answer, but this won't be handled by the server as pointed by by this SO post.
Going for approach 2, I have
POST /users/{id}/videos
to update the videos subresource of a user resource with a video via multipart uploadGET /users/{id}/videos/{file}
wherefile
can be "cat.mp4" or "dog.mp4"
This looks all nice and RESTy, but I'm unsure whether it's OK to to have the POST /users/{id}/videos
set cat_video_upload_date
and/or dog_video_upload_date
in the user resource, i.e. have a POST to a subresource implicitly trigger an update to the parent resource.
To sum this up: While both "just work", which approach of the two is The Right Way in terms of sticking to the true REST philosophy? Is there maybe another approach I haven't thought of?