By Yeyao from Xianyu Technology
With the gradual disappearance of client side traffic dividends, out-of-end placement has become one of the important drivers of seeking business growth. However, there are frontend containers born in different application scenarios and different periods on different apps:
When the business crosses ends, the frontend teams need to evaluate and adapt the target environment one by one. In the initial stage, the frontend is usually supported by maintaining multiple sets of implementations for different target environments for the same business, which multiplies the workload. Cross-end solutions have been created for efficiency improvement.
There is usually a large number of duplicate logic for cross-end JS API calls in the frontend code of the cross-end business:
if (isH5) {
if (isXianyu) { // Xianyu
webXianyuToast();
}else if (isTaobao) { // Taobao
webTaobaoToast();
} else if(isAlipay){ // Alipay
webAlipayToast()
}
// ...
} else if(isWeex)
// ...
These calls typically go through the following path from development to online:
Each step is a relatively time-consuming physical task. Hypothetically, it can meet the availability, usability, richness, and scalability so that the business can directly develop the following code and go online after normal testing. What problems should a cross-end API solution solve, and what capabilities should it provide?
import toast from 'uni-toast'
toast()
In the initial stage of the project, I learned that Xianyu and the frontend supporting the cross-end business of the entire Alibaba economy have the same problem. Therefore, the cross-end API project starts from the perspective of the economy and is promoted in a co-construction manner. The solution design for the preceding problems is listed below:
We define the overall cross-end API solution as three parts: specifications, SDKs, and supporting facilities:
The meaning of the cross-end API specifications is listed below:
Whether the specifications can be widely promoted and maintained depends on its rationality and upstream and downstream recognition. To ensure the two points above, authors of existing cross-end solutions in the economy are invited to set up a cross-end API specification group to formulate cross-end API specifications from the following four aspects:
1. Scope: What kind of API should be counted as a cross-end API?
Cross-end APIs should have cross-end attributes and high-frequency attributes: Cross-end attributes can be objectively reflected by the support of each container. On the one hand, high-frequency attributes are based on the call statistics of each scheme. On the other hand, they are judged by voting by members of the cross-end specification group one by one.
2. Environment Probe: The core of cross-end APIs is to call the corresponding implementation based on different environments. Accurate environment identification is particularly important.
Environmental identification involves standard containers and special containers inside and outside the economy. In the environmental probe specifications, the whole scenario is covered by the combination mechanism of container identification protocol, end identification protocol, system identification protocol, and identification order convention.
3. Standard API Definition: The standard API model is the interface of real APIs and the framework of all APIs.
Through the analysis of the standard API collection, the differences between APIs are mainly reflected in four parts: method naming, call method, output and input parameter structure, and returning error code. These four parts plus the input and output parameter extension mechanism define the standard API model.
4. Extension Mechanism: It is supported by customization and extension capabilities in scenarios that are not covered by the standard API collection. Extend a new end container implementation based on a standard API or extend a new API.
We began to implement the SDK using the specifications as the implementation basis and guidance. In the whole process, we mainly faced the following challenges:
window.uni.toast()
. The mode for cross-end basic material development is import toast from 'uni-toast'
. The use in multiple scenarios requires multi-form output.The key solution to the preceding challenges is:
uniapi-core
.If you have an environment-wide API atomization implementation, you can build a cross-end API solution with any degree of support. Several BU-level custom packages have been delivered.
The specifications and SDKs meet the requirements of availability, richness, and scalability. In terms of usability, cross-end APIs provide query and debugging capabilities for complex APIs, and internal and open-source sites have been built. Documentation (support information is detailed to parameters and app granularity), CANIUSE tools, and one-code multi-end call examples are provided.
After the cross-end API solution is connected, the workflow of the cross-end business is optimized like this:
Starting from the SDK 1.0 release, the social-networking community (Huiwan) of Xianyu began to pilot and land. The SDK Uni API has been applied to 10+ business units in the Alibaba economy and has gradually become the infrastructure developed at the frontend of the economy.
56 posts | 4 followers
FollowXianYu Tech - November 22, 2021
Alibaba Clouder - November 24, 2020
XianYu Tech - March 11, 2020
XianYu Tech - September 11, 2020
Alibaba Clouder - September 21, 2020
Alibaba Clouder - December 22, 2020
56 posts | 4 followers
FollowHelp enterprises build high-quality, stable mobile apps
Learn MoreAlibaba Cloud (in partnership with Whale Cloud) helps telcos build an all-in-one telecommunication and digital lifestyle platform based on DingTalk.
Learn MoreProvides comprehensive quality assurance for the release of your apps.
Learn MoreExplore Web Hosting solutions that can power your personal website or empower your online business.
Learn MoreMore Posts by XianYu Tech