Answer the question
In order to leave comments, you need to log in
Many small REST API requests or one big one?
There is a web application developed using components (VUE..JS, React, Angular). Some components of this application receive data via the REST API during initialization or during user interaction. This approach causes many API calls per page (sometimes more than 10).
Are there any problems with this approach?
Some suggest bundling API calls into larger client-side services that act as singletons. So 10 API calls can be reduced to 1, even though the page might only be using part of that data.
Which option is more correct, a lot of small requests or 1 big one?
Answer the question
In order to leave comments, you need to log in
If you now have something like this:
GET '/posts/slug/'
{
post: { /* ... */ }
}
GET '/posts/slug/comments/'
{
comments: { /* ... */ }
}
GET '/posts/slug/comments/users/'
{
users: { /* ... */ }
}
GET '/posts/slug/author/'
{
author: { /* ... */ }
}
GET '/posts/slug/meta/'
{
meta: { /* ... */ }
}
GET '/posts/slug/'
{
post: { /* ... */ },
linked: {
users: { /* ... */ },
comments: { /* ... */ },
meta: { /* ... */ },
},
}
graphql solves this, as it were,
Rest is not the only way to communicate client-server
I think that both options have the right to exist, they are not bad and not good. It all depends on the task, on the requirements, on how you will further develop the system, etc. You just need to know that the more requests - more network overhead, but you can only request what you need from the client, you can reuse the existing API in different application features. In the case of a complex model, the front works faster, there is no need to "glue the data", as a more complex query is executed on the back - this should be looked at. That is, each option has its pros and cons, and which method to choose depends on your specific task.
You need to watch, what difference does it make to you at the front? At least 100 requests if the server doesn't mind. Remember that you can do as you choose. If there are performance issues? Not? Kill it.
There are important points, such as the cache, the number of hits, and so on. How do you sample on the server side, did you optimize queries? What cache are you using? Etc
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question