For example, the homepage consists of multiple modules. Each module has its own API interface. the front-end staff asked me to return the data to him once, I need to combine the interfaces again. is this good? Or is it because he has obtained data from the front-end and back-end of the website through multiple requests:
For example, the homepage consists of multiple modules, each of which has its own API interface,
The front-end staff asked me to return the data to him once. I need to combine the interfaces,
Is this good? Or is it better for him to obtain data separately through multiple requests?
Reply content:
Website frontend and backend separation problems:
For example, the homepage consists of multiple modules, each of which has its own API interface,
The front-end staff asked me to return the data to him once. I need to combine the interfaces,
Is this good? Or is it better for him to obtain data separately through multiple requests?
I will introduce a more important solution, but may not answer your questions.
According to the concept of a large front end, if a Node layer is added in the middle, rendering can be performed on the front end on the server end, and the backend can be integrated with APIs. In addition, this is maintained by the front-end. if you don't want the back-end, you can do it yourself. :)
If the resources are the same or the resource consumption is small, do not write two interfaces for the same interface.
Highly Concurrent APIs such as Node and go. It is better not to send a message at a time. it is not good for restful APIs. This means that the backend is constantly changing as the front-end changes, and it is not suitable for decoupling and modularization. The front-end can cache and reduce interaction, such as redux and data cache. Don't get data from the backend every time, that is, getting data from the backend is a lot of interaction. A lot of data can be cached first after they are obtained, and there is a time interval or the user clicks the refresh and so on before getting data on the server.
After all, the fewer HTTP requests, the better. you can write more lines of code.
Different roles have different perspectives.
From the front-end perspective, a request may be returned, reducing http requests and improving performance. the front-end can send fewer requests.
From the back-end perspective, it is the module-based write interface, which is clear and clear.
I am a backend, and my general point of view is [I think it is appropriate, it is not difficult to develop, it does not affect you]. let's merge them together. in the returned data, you can also differentiate modules based on different keys. it is easy to add or delete modules later.
There is no need to compete for right or wrong roles. there is no absolute solution that is absolutely suitable for any situation and flexible handling.
Of course, you can stick to it.
If a large amount of data is returned, such as dozens of pages of paging data, the data must be obtained by Page.
If there are not many returned data and the performance is not affected due to the large amount of returned data (that is, negligible impact), we recommend that you return the data at a time, because this may greatly reduce the front-end workload, at the same time, because the number of requests for data is not very frequent, it is also good for performance.
Won't you use HTTP 2.0?
HTTP 2.0 requests are sent once and you deserve them.
In addition, if the background is RESTful, the combined interface breaks down the logic and is very damaging. If the frontend does not know RESTful, open it.
Yes. open an interface and combine the data of different modules as required. Different modules are encapsulated and called. this interface is also used for this purpose and should not be mixed.