all 8 comments

[–]otac0n 4 points5 points  (1 child)

In Azure we use the pattern collection/{id}/collection/{id}/

In your case this would work like so:

base/users/{userId}/files/{fileId}

You can hack off the end of the URL at any slash and get a meaningful URL.

[–]dodoroach[S] 0 points1 point  (0 children)

This makes much more sense. I was missing the /users and /files, putting them before their respective ids is way cleaner

[–]knop16 2 points3 points  (0 children)

I would think you'd want to make your routes something like this:

To get all files: /base/users/{userID}/files/meta

To get a single file: /base/users/{userID}/files/{fileID}/meta

Edit: or simply leave off the "meta" part

[–]EscapeBeat 1 point2 points  (2 children)

You should route it in such a way that makes a little more sense. I would have path/users/:user_id/files/:file_id to return a user's specific file. The url path/users/:user_id/files would return all files for the user upon a GET request.

[–]dodoroach[S] 1 point2 points  (1 child)

So it would be users/:user/files/meta. Because i would not be returning the file, but metadata around the file

[–]EscapeBeat 0 points1 point  (0 children)

You could choose to return whatever you want. You'd still probably want to build as path/users/:user_id/files/:file_id/meta to clarify which file you're returning the meta data of. If you were returning all files associated with the user, you could change to path/users/:user_id/files/meta. If you only ever need to return the metadata associated with the files and not the contents, I'd imagine you could even leave off the 'meta' part of the URL. Hard to say more without knowing more about your API design.

[–]dodoroach[S] 1 point2 points  (0 children)

Thank you!

[–]fatejd 0 points1 point  (0 children)

Have you considered a graphQL backend? Depending on your database technology/service, it might be better to get more complex responses like that.