Sends a network request via the native bridge.
The network request parameters including endpoint, method, headers, query, body, and timeout. See SendRequest.
The network response containing the result data or error information. See SendResponse.
Simple usage
import { NetworkModule, isSuccess, isError, hasResult } from '@grabjs/superapp-sdk';
// Initialize the network module
const network = new NetworkModule();
// Send a POST request with headers and body
const response = await network.send({
endpoint: 'https://api.example.com/users',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: { name: 'John', email: 'john@example.com' },
timeout: 30
});
// Handle the response
if (isSuccess(response) && hasResult(response)) {
console.log('Success:', response.result);
} else if (isError(response)) {
console.error(`Error ${response.status_code}: ${response.error}`);
} else {
console.error('Unhandled response');
}
JSBridge module for making network requests via the native bridge.
Remarks
Provides access to native network functionality for making HTTP requests. This module is only for MiniApps hosted on the Grab domain to call authenticated Grab API endpoints. It should not be used by external MiniApps (not on Grab domain) or for non-authenticated Grab APIs. This code must run on the Grab SuperApp's WebView to function correctly.
Example
ES Module:
Example
CDN (UMD):