M
M
Mors Clamor2019-10-24 10:56:08
RESTful API
Mors Clamor, 2019-10-24 10:56:08

What is the best way to build REST routing?

Hello. I know that there have already been such questions, but I would like to ask for the correctness of a particular option.
I also have the user entity, it has the post entity, respectively, it has comments, etc., that is, long chains can turn out.
Initially, I built api according to the
api/user/{id}/post/{id}/comments/{id} principle, but then I thought that it was inconvenient and crooked. It is supposed to be possible to receive both a list of all, for example, comments, and one specific one, so loading them immediately in the post entity is not an option.
At VK, I saw that, in principle, access goes to each entity separately, and the parameters are passed to GET
api/users?id={id}&fields={fields}...
I have no doubt about the professionalism of the VK team, but I saw a lot of all sorts of options on the Internet, including mine (more precisely, I borrowed it).
How is it right anyway?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Shumov, 2019-10-24
@66demon666

It is worth thinking more about how the API will be used. Just imagine - to get a comment you need to know the user and post id. Does the system need this complexity? I don't think so.
REST basically makes related entities this way only when they don't exist. as . a global list (for example, the user has a status and it must be changed separately GET users/:id/status, PUT users/:id/status)
But there is no right option, there is a suitable one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question