@grabjs/superapp-sdk
    Preparing search index...

    Class NetworkModule

    SDK module for making network requests through the native layer via JSBridge.

    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.

    ES Module:

    import { NetworkModule } from '@grabjs/superapp-sdk';
    const networkModule = new NetworkModule();

    CDN (UMD):

    <script src="https://cdn.jsdelivr.net/npm/@grabjs/superapp-sdk@x.y.z/dist/index.js"></script>
    <script>
    const networkModule = new SuperAppSDK.NetworkModule();
    </script>

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Sends a network request through JSBridge.

      Parameters

      Returns Promise<SendResponse>

      The network response containing the result data or error information. See SendResponse.

      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');
      }