SDKs overview
Grab offers Software Development Kits (SDKs) to facilitate the integration of its various services into third-party applications. These SDKs abstract much of the complexity of direct API interaction, providing developers with pre-built modules and functions to access features like ride-hailing, food delivery, logistics, and digital payments. The primary goal of these SDKs is to reduce development time and effort by offering platform-specific tools for common programming languages and mobile operating systems, as detailed in the Grab developer documentation.
Developers can utilize these SDKs to embed Grab functionalities directly into their applications. For instance, a travel app might integrate the Grab Transport SDK to offer ride-booking options to its users, or an e-commerce platform could use the Grab Pay SDK for in-app payment processing. The SDKs typically handle aspects such as authentication, request formatting, and response parsing, allowing developers to focus on their application's core logic.
Official SDKs by language
Grab provides official SDKs for popular development environments, ensuring robust and supported integrations. These SDKs are maintained by Grab and are designed to work seamlessly with the Grab API reference. The following table summarizes the key official SDKs:
| Language/Platform | Package/Module | Install Command (Example) | Maturity |
|---|---|---|---|
| JavaScript (Web) | @grab-developer/grab-js-sdk |
npm install @grab-developer/grab-js-sdk |
Stable |
| Android (Java/Kotlin) | com.grab.sdk:android-sdk |
Add to build.gradle dependencies |
Stable |
| iOS (Swift/Objective-C) | GrabSDK (CocoaPods) |
pod 'GrabSDK' |
Stable |
Each SDK is designed to provide a native-like experience for its respective platform, adhering to common development patterns and conventions. For example, the Android SDK integrates with the Android lifecycle, while the iOS SDK leverages Swift and Objective-C best practices. These SDKs are regularly updated to reflect new API features and improvements, as outlined in the Grab developer portal.
Installation
The installation process varies slightly depending on the chosen SDK and development environment. Developers should refer to the specific documentation for each SDK on the Grab developer documentation for the most up-to-date instructions. Below are general guidelines for installing the official Grab SDKs:
JavaScript SDK
For web applications, the Grab JavaScript SDK can be installed via npm, a package manager for JavaScript. This approach integrates the SDK into your project's build system.
npm install @grab-developer/grab-js-sdk
Alternatively, the SDK can be included directly in an HTML file via a CDN link for simpler projects or testing purposes:
<script src="https://sdk.grab.com/js/v1/grab-sdk.min.js"></script>
Android SDK
The Grab Android SDK is distributed through Maven. To include it in an Android project, add the dependency to your app's build.gradle file:
dependencies {
implementation 'com.grab.sdk:android-sdk:latest.version'
}
Ensure that the Maven repository is declared in your project's top-level build.gradle file:
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://developer.grab.com/maven' }
}
}
iOS SDK
For iOS projects, the Grab SDK is typically integrated using CocoaPods, a dependency manager for Swift and Objective-C Cocoa projects. First, ensure CocoaPods is installed. Then, create or update your Podfile:
platform :ios, '11.0'
target 'YourAppTarget' do
use_frameworks!
pod 'GrabSDK'
end
After saving the Podfile, run the installation command:
pod install
This will integrate the Grab SDK into your Xcode project. Developers should consult the Grab API reference documentation for the specific versioning and detailed setup steps.
Quickstart example
This quickstart example demonstrates how to initialize the Grab JavaScript SDK and make a basic API call to retrieve available transport options. This snippet assumes you have obtained a client ID from the Grab developer dashboard.
// Initialize the Grab SDK
// Replace 'YOUR_CLIENT_ID' with your actual Grab developer Client ID
// Replace 'YOUR_REDIRECT_URI' with the URI configured in your Grab developer dashboard
const grabSDK = new GrabSDK({
clientId: 'YOUR_CLIENT_ID',
redirectUri: 'YOUR_REDIRECT_URI',
// For production, use 'production'. For testing, use 'sandbox'.
env: 'sandbox'
});
// Example: Authenticate the user (required for most API calls)
// This will redirect the user for login/consent if not already authenticated
grabSDK.authenticate().then(user => {
console.log('User authenticated:', user);
// After authentication, you can make API calls
// Example: Get available transport products at a specific location
const latitude = 1.3521; // Example: Singapore latitude
const longitude = 103.8198; // Example: Singapore longitude
grabSDK.transport.getProducts({
lat: latitude,
lng: longitude
}).then(products => {
console.log('Available transport products:', products);
// Process the list of products (e.g., display them in UI)
}).catch(error => {
console.error('Error fetching transport products:', error);
});
}).catch(error => {
console.error('Authentication failed:', error);
});
// For a more comprehensive understanding of the authentication flow and other services,
// refer to the official Grab JavaScript SDK documentation on the Grab developer portal.
This example illustrates the typical pattern of initializing the SDK, authenticating a user (which is often a prerequisite for accessing user-specific data or initiating transactions), and then making a service-specific API call. The authenticate() method initiates an OAuth 2.0 flow, which is a common authorization framework used by many APIs, including those from OAuth.net for authorization. Developers should manage their client IDs and redirect URIs securely and configure them correctly in the Grab developer portal to ensure proper functionality and security.
Community libraries
While Grab provides official SDKs for its core services, the open-source community may develop unofficial libraries or wrappers in other programming languages or for specific frameworks. These community-contributed tools can sometimes extend the reach of Grab's APIs to environments not directly supported by official SDKs, or offer alternative implementations that suit particular development preferences.
However, it is important to note that community libraries are not officially maintained or supported by Grab. Their reliability, security, and compatibility with the latest API changes can vary. Developers considering using community libraries should:
- Verify the source: Check the reputation of the maintainers and the project's activity on platforms like GitHub.
- Examine the code: Review the codebase for security vulnerabilities and adherence to best practices, especially when handling sensitive data or authentication credentials.
- Test thoroughly: Conduct extensive testing to ensure the library functions as expected and integrates correctly with the Grab API.
- Monitor for updates: Be prepared to adapt to API changes independently, as community libraries may not be updated as frequently or reliably as official SDKs.
Currently, the Grab developer documentation primarily highlights its official SDKs. Developers seeking community libraries are advised to search public code repositories and developer forums, exercising due diligence before integrating any unofficial solution into a production environment. For any mission-critical integrations, using the official SDKs or direct API calls is generally recommended for stability and support.