M
M
Mors Clamor2019-10-19 19:07:12
API
Mors Clamor, 2019-10-19 19:07:12

Where is the right place to make requests to the API - JS or PHP?

Hello! I'm displaying a list of user's posts by ajax request. To do this, I use the html template and mustache. Getting the text of the post and its rating - one request, getting the author's information - avatar, nickname, id - the second request. Checking the possibility of liking a post is the third request. Mustache requires all data to be in a one-dimensional array in order for it to be substituted into variables. How would it be more correct to do it - 3 ajax requests and then just blind everything into a one-dimensional array, or still send a request to the server so that it makes a request to the api through curl and returns the answer in the desired format? Because the option to return all this in general through one api method does not make sense. thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2019-10-19
@66demon666

Draw design components separately from each other. Why do you need to render all three requests at once?
What if one fails? What if one returns the wrong result?
The React library looks great in this methodology. There, each component lives its own life. You need to do the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question