REST API Documentation
Dokumentasi penggunaan Public REST API. Gunakan API Key untuk mengakses endpoint dan mengelola data melalui request HTTP.
https://api.domainkamu.com/api/v1
Authentication
Semua request API membutuhkan API Key melalui HTTP header X-API-Key.
X-API-Key: YOUR_API_KEY
Penting: Jangan menaruh API Key di URL atau source code frontend yang dapat dilihat publik.
Contoh
curl -X GET \
-H "X-API-Key: YOUR_API_KEY" \
https://api.domainkamu.com/api/v1/users
Quick Start
1. Dapatkan API Key
Hubungi administrator/provider API untuk mendapatkan API Key.
2. Tentukan Base URL
Gunakan Base URL yang diberikan administrator.
https://api.domainkamu.com/api/v1
3. Kirim request
Sertakan API Key pada header X-API-Key.
4. Baca response JSON
API mengembalikan data dan informasi error dalam format JSON.
Users
GET
/users
Mengambil daftar user.
Query Parameters
| Parameter | Type | Default | Keterangan |
|---|---|---|---|
| page | integer | 1 | Nomor halaman. |
| limit | integer | 20 | Jumlah data, maksimum 100. |
Request
curl -X GET \
-H "X-API-Key: YOUR_API_KEY" \
"https://api.domainkamu.com/api/v1/users?page=1&limit=20"
Response
{
"success": true,
"data": [
{
"id": 1,
"name": "Budi",
"email": "budi@example.com",
"created_at": "2026-09-01 10:00:00",
"updated_at": "2026-09-01 10:00:00"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 1,
"total_pages": 1
}
}
Get User
GET
/users/{id}
Mengambil satu user berdasarkan ID.
curl -X GET \
-H "X-API-Key: YOUR_API_KEY" \
https://api.domainkamu.com/api/v1/users/1
Response
{
"success": true,
"data": {
"id": 1,
"name": "Budi",
"email": "budi@example.com",
"created_at": "2026-09-01 10:00:00",
"updated_at": "2026-09-01 10:00:00"
}
}
Create User
POST
/users
Membuat user baru.
Headers
Content-Type: application/json
X-API-Key: YOUR_API_KEY
Body
{
"name": "Widi",
"email": "widi@example.com"
}
Request
curl -X POST \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{"name":"Widi","email":"widi@example.com"}' \
https://api.domainkamu.com/api/v1/users
Response 201 Created
{
"success": true,
"message": "User created",
"data": {
"id": 3,
"name": "Widi",
"email": "widi@example.com"
}
}
Update User
PUT
/users/{id}
Mengubah data user berdasarkan ID.
Body
{
"name": "Widi Coding",
"email": "widi@example.com"
}
Request
curl -X PUT \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{"name":"Widi Coding","email":"widi@example.com"}' \
https://api.domainkamu.com/api/v1/users/3
Response
{
"success": true,
"message": "User updated"
}
Delete User
DELETE
/users/{id}
Menghapus user berdasarkan ID.
curl -X DELETE \
-H "X-API-Key: YOUR_API_KEY" \
https://api.domainkamu.com/api/v1/users/3
Response
{
"success": true,
"message": "User deleted"
}
HTTP Status & Errors
| Status | Keterangan |
|---|---|
| 200 | Request berhasil. |
| 201 | Data berhasil dibuat. |
| 400 | Request tidak valid. |
| 401 | API Key tidak ada, tidak valid, atau expired. |
| 404 | Endpoint atau data tidak ditemukan. |
| 405 | HTTP method tidak didukung. |
| 409 | Data conflict, misalnya email sudah digunakan. |
| 422 | Data input tidak valid. |
| 429 | Rate limit terlampaui. |
| 500 | Internal server error. |
Contoh Error
{
"success": false,
"message": "Invalid API key"
}
Rate Limit
Setiap API Key memiliki batas request. Default template adalah 60 request per 60 detik.
{
"success": false,
"message": "Rate limit exceeded",
"retry_after_seconds": 42
}
Jika menerima HTTP 429, tunggu selama retry_after_seconds sebelum melakukan request berikutnya.
Code Examples
JavaScript
fetch("https://api.domainkamu.com/api/v1/users", {
method: "GET",
headers: {
"X-API-Key": "YOUR_API_KEY"
}
})
.then(response => response.json())
.then(data => console.log(data));
PHP
<?php
$url = "https://api.domainkamu.com/api/v1/users";
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"X-API-Key: YOUR_API_KEY"
]
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
print_r($data);
Python
import requests
url = "https://api.domainkamu.com/api/v1/users"
headers = {
"X-API-Key": "YOUR_API_KEY"
}
response = requests.get(url, headers=headers)
print(response.status_code)
print(response.json())
Security
API Key adalah credential. Jangan memasukkannya ke URL, Git repository publik, screenshot, atau frontend JavaScript yang dapat dilihat user.
- Gunakan HTTPS.
- Simpan API Key di environment/config private.
- Jangan commit API Key ke GitHub public.
- Jika key bocor, segera nonaktifkan dan buat key baru.
- Jangan mengirim API Key melalui query string.