Base URL & Endpoint
Cấu trúc endpoint chung của hệ thống.
Base URL là gì?
Base URL (URL cơ sở) là địa chỉ gốc mà tất cả các API endpoint của hệ thống đều bắt đầu từ đó. Khi gọi API, bạn cần nối thêm đường dẫn cụ thể vào Base URL để tạo thành URL hoàn chỉnh.
URL môi trường Production
Base URL
http://localhost:9090
Cấu trúc URL API
Tất cả API endpoint đều tuân theo cấu trúc RESTful:
Cấu trúc
{BASE_URL}/api/{resource}/{action}
# Ví dụ:
http://localhost:9090/api/auth/login
http://localhost:9090/api/user/info
http://localhost:9090/api/packages
http://localhost:9090/api/keys
Nhóm Resource chính
| Resource | Mô tả | Ví dụ Endpoint |
|---|---|---|
/api/auth |
Xác thực người dùng (đăng ký, đăng nhập, token) | /api/auth/login |
/api/user |
Quản lý thông tin người dùng | /api/user/info |
/api/packages |
Quản lý gói ứng dụng | /api/packages |
/api/keys |
Quản lý API Keys | /api/keys |
/api/namekeys |
Quản lý tiền tố Key | /api/namekeys |
/api/vip |
Quản lý mã VIP | /api/vip/redeem |
HTTP Methods
Hệ thống sử dụng các HTTP method chuẩn RESTful:
| Method | Mục đích | Ví dụ |
|---|---|---|
GET |
Lấy dữ liệu | GET /api/keys - Lấy danh sách key |
POST |
Tạo mới dữ liệu | POST /api/keys - Tạo key mới |
PUT |
Cập nhật dữ liệu | PUT /api/keys/{id} - Cập nhật key |
DELETE |
Xóa dữ liệu | DELETE /api/keys/{id} - Xóa key |
Ví dụ tích hợp
Lưu ý quan trọng
Luôn sử dụng HTTPS cho mọi request. Hệ thống không hỗ trợ HTTP.
JavaScript (Fetch)
javascript
const BASE_URL = 'http://localhost:9090';
// Lấy danh sách packages
const response = await fetch(`${BASE_URL}/api/packages`, {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);
PHP (cURL)
php
$baseUrl = 'http://localhost:9090';
$token = 'YOUR_TOKEN';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/api/packages');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
Python (requests)
python
import requests
BASE_URL = 'http://localhost:9090'
TOKEN = 'YOUR_TOKEN'
headers = {
'Authorization': f'Bearer {TOKEN}',
'Content-Type': 'application/json'
}
response = requests.get(f'{BASE_URL}/api/packages', headers=headers)
data = response.json()
print(data)
Best Practices
Khuyên dùng
- Lưu BASE_URL vào biến môi trường hoặc config file
- Sử dụng HTTPS để bảo mật dữ liệu
- Xử lý timeout và retry cho network errors
- Cache token để tránh đăng nhập lại nhiều lần
© 2026 CTDOAPIKEY Documentation