java - APP接口开发方案探讨
大家讲道理
大家讲道理 2017-04-17 17:21:11
0
10
343

后端再开发APP接口时,例如是一个电商型的APP,那个在个人中心的页面上会有用户的个人资料用户的购物车数量用户的余额信息推荐的商品等等的一些相关的东西,那么对于接口来说,是应该在APP的一次请求中返回页面包含的所有内容?还是应该针对资源让APP多次请求获取?如果应该一次性请求的且接口为RESTFul风格的话要如何设计请求及返回内容更加合理?

补充一下,减少网络请求我固然知道是对网络而言是更好的,但是在减少网络请求的同时必然会造成请求内容过大,用户等待时间可能更长,而且在RESTFul风格的API下,如何设计会更加合理?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(10)
小葫芦

I personally use multiple requests artificially and in practice. This ensures the flexibility of the app, facilitates server-side sub-module development, and ensures maintainability. And most of the time, loading some data that users don't commonly use wastes user traffic.

迷茫

Of course it needs to be separated. The app uses asynchronous requests. You can load some data first and divide it according to the level

Peter_Zhu

It is generally recommended to make as few network requests as possible. However, for some data that does not require high timeliness, local caching can be used, such as personal data.

黄舟

It depends on the complexity of your current service architecture:
If it is centralized: it is convenient, according to the current service scale (startup company)
If it is distributed: different data comes from different service interfaces (mature company) )

Supplement: E-commerce is constant reconstruction, reconstruction is decoupling, and decoupling is interface-oriented programming

小葫芦

The answers above are all very good. In addition, the author can take a look at the pipeline design of redis. For example, basic user information and shopping cart information need to be displayed on a main page. They can be made in the same http request. Send multiple commands, and then the server returns the content one by one.

Of course the server-side design must be modularized, so the backend of this batch command request method may need a module to receive commands to analyze the commands and then delegate it to the actual module to get the results.#🎜🎜 #

小葫芦

If the questioner knows something about network requests, he should know that when the user information is not large, it is better to request all user information at once. Because connection loss is inevitable.

Peter_Zhu

You can filter the data for the business, for example, it is related to money or the quantity of goods. The request frequency can be higher. For example, the front-end cache of personal data can use some appropriate strategies to determine whether to read the cache or re-obtain it from the server...No Get them all at once, cache them all, and don't make requests too frequently.

Four words

微服务化
迷茫

Since you are asking about RESTful APIs, it is natural to classify them by resource type, not by page. That is to say, when you design the API, you don't have to consider how the client organizes resources, but based on the database structure of your server. Generally speaking, a table corresponds to a Model, and a Model corresponds to a request. Of course, sometimes there are some special needs in actual projects, and I will make some changes, which may not strictly follow this model.

阿神

I have always had this question. According to the resources, the change of the app page will basically not have much impact. If it follows the page, as long as the product side says it needs to be changed, the previous interface will be basically useless. However, some friends on the client side like to follow the page

刘奇

Choose based on the semantics of the interface. I feel that there is no unified answer to this kind of question. It’s ok if you feel comfortable with it

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!