Skip to main content
The framework provides developers with JSAPI and OpenAPI capabilities to launch diversified convenient services to users. This section covers the client-side JavaScript APIs (JSAPI) that Mini Apps can use to interact with the platform and device features.

API Patterns

Mini Program JSAPIs follow two main patterns:

Event Listening APIs

APIs prefixed with my.on listen to system events and accept callback functions. When the event is triggered, the callback is executed.
// Register event listener
my.onAppShow((res) => {
  console.log('App became visible', res);
});

// Unregister specific listener
my.offAppShow(callback);

// Unregister all listeners for an event
my.offAppShow();
Always clean up event listeners when they’re no longer needed, such as in page onUnload lifecycle hooks, to prevent memory leaks.

Standard Interface APIs

Most other APIs accept an object as a parameter and support three callback types:
CallbackDescription
successCalled when the operation completes successfully
failCalled when the operation fails
completeAlways called after success or fail
my.getLocation({
  success: (res) => {
    console.log('Location:', res.latitude, res.longitude);
  },
  fail: (err) => {
    console.error('Failed:', err.errorMessage);
  },
  complete: () => {
    console.log('Operation finished');
  }
});

Promise Support

APIs also return Promise objects, allowing both callback and async/await patterns:
// Using Promise .then()
my.request({
  url: 'https://api.example.com/data'
}).then((res) => {
  console.log('Success:', res.data);
}).catch((err) => {
  console.error('Error:', err.errorMessage);
});

// Using async/await
async function fetchData() {
  try {
    const res = await my.request({
      url: 'https://api.example.com/data'
    });
    console.log('Success:', res.data);
  } catch (err) {
    console.error('Error:', err.errorMessage);
  }
}

API Categories

Basic

Core APIs for version checking and feature detection

In-App Event

App lifecycle and error event handling

UI

Navigation, feedback, dialogs, and UI controls

Media

Image, video, and animation handling

Storage

Local data persistence

File

File system operations

Location

Geolocation services

Map

Map integration and routing

Network

HTTP requests and WebSocket connections

Device

Hardware and system information

Sharing

Content sharing capabilities

Update

App update management

web-view

WebView integration

Open Capabilities

Authentication, payments, and cross-app navigation

Feature Detection

Before using an API, you can check if it’s supported in the current environment:
if (my.canIUse('getLocation')) {
  my.getLocation({
    success: (res) => {
      console.log(res);
    }
  });
} else {
  console.log('getLocation is not supported');
}
Always use feature detection for APIs that may not be available on all platform versions. This ensures your Mini App degrades gracefully on older versions.

Next Steps

JSAPI Reference

Complete API reference by category

JS Bridge Guide

Cross-app launch integration