All Products
Search
Document Center

Custom API

Last Updated: Feb 04, 2021

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:

Note: The custom APIs only support calling native pages from the mini program page, but not the reverse.

Call APIs in Mini Program

Use the following method in Mini Program to call a custom API:

  1. 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:

  1. my.call('rpc', {
  2. operationType: 'com.test.mb1001',
  3. requestData: [{
  4. tranCode: 'MB1001',
  5. customerType: 0,
  6. customerId: 0,
  7. UnitType: '7A238BD3-A90B-4458-885E-129230BCF7F1',
  8. sessionId: 'zzzzzzzzzzzzzzzz',
  9. serverIP: 'zzzzzzzzzzzzzzzz',
  10. mobileNo: username,
  11. password,
  12. optionFlag: 3,
  13. }]
  14. }, (res) => {
  15. // do your business here.
  16. })

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.