Skip to main content
Version: 12.10.0

API Module

The API and Network Abstraction Module is a OpenContract Module protocol that provides a standardized interface for handling API calls, supporting various HTTP methods like GET, POST, PUT, and DELETE. It allows setting the base URL and choosing between different authentication methods, such as JWT and OAuth2. The module includes features like a retry mechanism, response parsing, and customizations for headers, query parameters, and request/response interceptors. Components can use this module to make API calls without worrying about network details and authentication complexities.

This module should tackle all challenges reguarding API requests, token handling, retry logic and errors.

All the plugin should call executeAPI () to invoke the APIs

API Requests

Retry Logic

retry mechanism that automatically retries failed API requests with a configurable retry count and interval. The class handles API responses and errors, ensuring appropriate retry attempts based on specific conditions. Components can use this module to perform various API calls, benefiting from the built-in retry mechanism without having to manage network details or retry logic themselves.

Error handling

Handling errors in a Mobile API/Network Abstraction Module is essential to provide meaningful feedback to the calling components and ensure that they can react appropriately to different scenarios. Errors can occur at various stages of an API request, such as network issues, server errors, or parsing problems.

Authentication mechanisms

oAuth2.0

JWT Based

The below sequence diagram provides an overview of the interactions and communication flow between different components in the system during the JWT-based authentication and API call process. It illustrates the successful acquisition and usage of the JWT token for making API calls, as well as the retry mechanism to handle any temporary failures during the API call process.

The mobile app (App) sends a GET request to the API server (Server) through the module. The module includes the JWT token in the request headers when making the API call. The API server (Server) responds to the module with the requested data. The module forwards the data to the mobile app (App) as the response.

Retry Mechanism for jwt:

In case of a failure in the initial API call, the module initiates a retry mechanism. The module retries the API call to the API server (Server) with the same JWT token. The API server (Server) responds with an error. The module increments the retry count to keep track of retries. If the retry limit is exceeded, the module notifies the plugin with a failure message. Otherwise, the module retries the API call by triggering the "Retry the API Call" step.