A
A
Artem00712018-03-23 22:24:17
API
Artem0071, 2018-03-23 22:24:17

REST API Best Practice?

There was an article on Habré , but like in other such posts, I could not find one, but important thing for myself.
Everywhere only certain categories are described, such as /catsor /dogs
But what to do with the option in which we need to get not only the model or not only his friends , but the model and additional parameters, for example, with dashbord'e? That is, we get a certain base on the "cat" and some more data that is on the page
. How can I get cat and all his friends?
/cats/1(id некого кота)/friends?
Okay, but what if I need to get not only his friends, but also some additional information, such as trays in which he ...?
/cats/1/friends_and_wc? but this is stupid, we can make a mistake in writing in a certain order, and there can be more than 2 options
or
/cats/1/frieds/wc?
Or will we have to create 2 separate queries?
Or should we use some additional parameters?
For example
/cats/1?extra=friends,wc
In general, is there any "Best Practice" solution here?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-03-24
@Artem0071

Best Practice is to design loosely coupled systems, and not to hang a bunch of functions on one endpoint.

V
Vitaly, 2018-03-24
@vshvydky

in my opinion, gql can also be used in simple queries.
for me, there is no need to cycle at the model level, since this is the concept of simple and not very dependent on each other data. we call the endpoint the name of the table and the query method determines what we are doing with it, this is the blog or news list level.
But what about when, when accessing 1 endpoint, a request is made to the database for 100 rows? what gql is there? all these simplifications for ordinary and daily tasks, if you need to perform non-trivial actions, then you need to plan your API concept and forget about recommendations that limit you.
e.g. /api/entity/action
Why even think about how others will look at your objectively necessary classification of api names? you have a task, you solve it and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question