All Products
Search
Document Center

Mobile Platform as a Service:Custom API

Last Updated:Feb 03, 2023

If the existing mini program APIs cannot meet your requirements, you can extend customize APIs by yourself. Mini program APIs use the JSAPI plug-in mechanism of the HTML5 container, which means that you can customize APIs according to the plug-in mechanism provided by the HTML5 container, and your mini program can directly call JSAPIs that you have written.

If the existing mini program APIs cannot meet your requirements, you can extend customize APIs by yourself. Mini program APIs use the JSAPI plug-in mechanism of the HTML5 container, which means that you can customize APIs according to the plug-in mechanism provided by the HTML5 container, and your mini program can directly call JSAPIs that you have written.

Custom APIs

To customize APIs, see the Custom JSAPIs topic of the HTML5 container document:

Note: The custom mini program APIs only support calling native components from the page, but do not allow the native components to proactively send events to the page.

Call API in the mini program

Use the following method in the mini program to call a customized API:

my.call(API, param, callback)

In which:

  • 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 mini program calls and HTML5 calls, see the Call the RPC API topic of the HTML5 container document.