C
C
cyberz2019-07-18 12:58:01
RESTful API
cyberz, 2019-07-18 12:58:01

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

5 answer(s)
A
Anton Spirin, 2019-07-18
@rockon404

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: { /* ... */ }
}

then it is logical to combine all related data into one query:
GET '/posts/slug/'

{
  post: { /* ... */ },
  linked: {
    users: { /* ... */ },
    comments: { /* ... */ },
    meta: { /* ... */ },
  },
}

M
Michael, 2019-07-18
@notiv-nt

graphql solves this, as it were,
Rest is not the only way to communicate client-server

A
asdz, 2019-07-18
@asdz

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.

A
AlexisKmetik, 2019-07-19
@AlexisKmetik

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

I
Igor, 2019-07-20
@IgorPI

Imagine that one client conditionally makes 100 requests to a server
of 100 * 1000 clients.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question