A
A
Andrey Okhotnikov2019-04-29 12:59:35
RESTful API
Andrey Okhotnikov, 2019-04-29 12:59:35

What is the best way to get data from several endpoints?

When loading a page via Rest, I receive data from 3 endpoints - user, products, banners - at the moment I make requests independently from each other in different actions. Is it right to do this, or do I need to combine several requests into one, for example, through axios.all ?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Anton Spirin, 2019-04-29
@rockon404

User data, in a good way, should be requested in the application initialization action, and the loading of goods should be initiated in the cdm of the product page.

D
Dima Pautov, 2019-04-29
@bootd

axios.all will make 3 requests anyway, but using
promise.all

R
Rodion Almetov, 2019-04-29
@radar4ick

If you really want to fix three requests for one, you can create one common controller that will collect data from 3 other controllers and send everything in one response

P
Pavel Pikat, 2019-04-29
@PavelPikat

REST implies a lot of endpoints that will be called independently of each other, so overfetching for applications with a REST backend is the norm. If this becomes a problem in terms of performance / traffic, then you need to think about combining either queries or endpoints, or leave REST altogether, for example, in GraphQL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question