Authentication overview
The Indonesia Dictionary API secures access to its language translation and dictionary services primarily through API key authentication. This method requires developers to obtain a unique key associated with their account and include it with every API request. The API key serves as a credential to verify the identity of the requesting application and to enforce usage limits based on the user's subscription plan, which includes a free tier for up to 500 requests per month. By requiring an API key, the Indonesia Dictionary platform manages access, monitors usage, and protects its resources from unauthorized or excessive requests. This approach is common for public APIs that prioritize ease of integration while maintaining control over access and resource consumption, as detailed in the Indonesia Dictionary API documentation.
Supported authentication methods
Indonesia Dictionary's API supports authentication primarily through a single method: API keys. This method is suitable for most applications requiring direct access to dictionary functionalities. Below is a summary of the supported authentication method:
| Method | When to Use | Security Level |
|---|---|---|
| API Key | Server-side applications, mobile apps (with backend proxy), or static websites requiring simple, direct access to the dictionary API. | Moderate (requires secure storage and transmission) |
API keys are typically transmitted either in the HTTP Authorization header or as a query parameter. While query parameters can be simpler for initial setup, using an HTTP header is generally recommended for enhanced security, as it prevents the key from being logged in server access logs or browser history, which could expose the credential. The Cloudflare API Key management guide offers additional insights into securing API key usage.
Getting your credentials
To access the Indonesia Dictionary API, you must first obtain an API key. This process involves registering for an account on the Indonesia Dictionary website and then navigating to your user dashboard. The steps are as follows:
- Register for an Account: Visit the Indonesia Dictionary homepage and sign up for a new account if you do not already have one. This typically involves providing an email address and creating a password.
- Access Your Dashboard: After successful registration and login, navigate to your personal dashboard or API settings section. The exact path may vary but is usually labeled prominently as "API Keys," "Developer Settings," or "Dashboard."
- Generate or Retrieve API Key: Within the dashboard, you will find an option to generate a new API key or retrieve an existing one. If no key exists, follow the prompts to create one. The platform will display your unique API key, which is a string of alphanumeric characters.
- Securely Store Your Key: Once generated, copy your API key and store it securely. Treat your API key as sensitive information, similar to a password. Avoid hardcoding it directly into client-side code or committing it to public version control systems.
- Review Usage Limits: Familiarize yourself with the API usage limits associated with your account tier, including the free tier's 500 requests per month, to ensure your application operates within allowed parameters.
For detailed instructions, refer to the official Indonesia Dictionary API documentation.
Authenticated request example
Once you have obtained your API key, you can include it in your API requests. The Indonesia Dictionary API typically expects the API key to be passed either as an HTTP header or as a query parameter. Below are examples demonstrating how to make an authenticated request using both methods, with a focus on the recommended header-based approach.
Using an HTTP Header (Recommended)
This method involves sending your API key in the X-API-Key header (or similar, as specified in the API documentation). This is generally more secure as it prevents the key from being exposed in URLs.
Python Example (using requests library):
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.indonesiandictionary.com"
ENDPOINT = "/v1/translate"
headers = {
"X-API-Key": API_KEY,
"Content-Type": "application/json"
}
params = {
"text": "hello",
"from": "en",
"to": "id"
}
response = requests.get(f"{BASE_URL}{ENDPOINT}", headers=headers, params=params)
if response.status_code == 200:
print(response.json())
else:
print(f"Error: {response.status_code} - {response.text}")
JavaScript Example (using fetch API):
const API_KEY = "YOUR_API_KEY";
const BASE_URL = "https://api.indonesiandictionary.com";
const ENDPOINT = "/v1/translate";
const textToTranslate = "world";
const fromLang = "en";
const toLang = "id";
fetch(`${BASE_URL}${ENDPOINT}?text=${textToTranslate}&from=${fromLang}&to=${toLang}`, {
method: 'GET',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
}
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error fetching data:', error);
});
Using a Query Parameter (Less Recommended)
If the API documentation specifically allows or requires it, you can also pass the API key as a query parameter. However, this method is generally less secure.
Python Example (using requests library):
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.indonesiandictionary.com"
ENDPOINT = "/v1/translate"
params = {
"text": "goodbye",
"from": "en",
"to": "id",
"apiKey": API_KEY # Key passed as a query parameter
}
response = requests.get(f"{BASE_URL}{ENDPOINT}", params=params)
if response.status_code == 200:
print(response.json())
else:
print(f"Error: {response.status_code} - {response.text}")
Always verify the exact parameter name (e.g., apiKey, key, or api_key) and its expected location by consulting the Indonesia Dictionary API reference.
Security best practices
Securing your API keys is critical for protecting your account and ensuring uninterrupted access to the Indonesia Dictionary API. Adhering to these best practices helps mitigate common security risks:
- Never Expose API Keys in Client-Side Code: Direct exposure of API keys in front-end JavaScript, mobile app binaries, or other client-side code allows anyone to view and potentially misuse your key. Always route API requests through a secure backend server.
- Use Environment Variables: Store API keys as environment variables on your server or in your development environment rather than hardcoding them directly into your application's source code. This prevents accidental exposure in version control systems.
- Implement a Backend Proxy: For client-side applications (e.g., single-page applications, mobile apps), implement a secure backend proxy server. The client application calls your backend, which then makes the authenticated request to the Indonesia Dictionary API using your securely stored API key. This pattern is described in various Google API client library authentication guides.
- Restrict API Key Privileges: While Indonesia Dictionary API keys generally grant access to dictionary functions, if future versions introduce granular permissions, always restrict keys to the minimum necessary privileges.
- Regularly Rotate API Keys: Periodically generate new API keys and revoke old ones. This practice reduces the window of opportunity for a compromised key to be exploited.
- Monitor Usage: Regularly check your API usage statistics on the Indonesia Dictionary dashboard to detect any unusual activity that might indicate a compromised key.
- Secure Your Development Environment: Ensure that your development machines and local environments are secure, as API keys stored locally can also be vulnerable.
- Use HTTPS: Always make API requests over HTTPS to encrypt the communication channel and protect your API key from interception during transit. The Indonesia Dictionary API inherently requires HTTPS.
- Implement Rate Limiting and Quotas: While the Indonesia Dictionary API enforces its own rate limits, consider implementing client-side rate limiting within your application to prevent accidental overuse and to provide a buffer against potential DoS attacks if your key is exposed.
By following these guidelines, you can significantly enhance the security posture of your application when integrating with the Indonesia Dictionary API.