Mini Program supports custom API. If the existing mini program API cannot meet your need, you can extend the APIs on demand. The API of the Mini Program uses the JSAPI plug-in mechanism of the H5 Container, which means that you can extend APIs according to the plug-in mechanism provided by the H5 Container, and your mini program can directly call custom APIs that you have written.
Customize APIs
To customize APIs, see H5 Container’s Custom JSAPIs related documents:
Call APIs in Mini Program
Use the following method in Mini Program to call a custom API:
my.call(API, param, callback)
The details are as follows:
- API: the name of the custom API.
- param: the parameters that are used to call the API.
- callback: the callback function that is executed by the API.
Take calling the rpc
method as an example, the code sample is as follows:
my.call('rpc', {
operationType: 'com.test.mb1001',
requestData: [{
tranCode: 'MB1001',
customerType: 0,
customerId: 0,
UnitType: '7A238BD3-A90B-4458-885E-129230BCF7F1',
sessionId: 'zzzzzzzzzzzzzzzz',
serverIP: 'zzzzzzzzzzzzzzzz',
mobileNo: username,
password,
optionFlag: 3,
}]
}, (res) => {
// do your business here.
})
To understand the similarities and differences between the mini program and H5 calls, see the RPC topic of the H5 container JSAPI document.
Cancel the registration of custom events
If you do not need custom events, see Cancel the registration of custom events.