Tài Liệu API

v3.0
Smart Storage API

Tài Liệu API v3.0

Hướng dẫn chi tiết về API lưu trữ thông minh với key tự sinh và tìm kiếm theo nội dung

Tính năng mới v3.0
Lưu trữ thông minh với key tự sinh

🔑 Key tự sinh

Không cần nhập key - hệ thống tự động sinh key unique cho mỗi dữ liệu

🔍 Tìm kiếm theo nội dung

Tìm kiếm dữ liệu dựa trên nội dung thay vì key - hỗ trợ tìm chính xác và tìm một phần

⚡ Tự động hóa hoàn toàn

Chỉ cần gửi dữ liệu - mọi thứ khác được xử lý tự động

Xác thực API
Tất cả yêu cầu API đều cần xác thực bằng API key

Header bắt buộc:

X-API-Key: your-api-key-here
Các Thao tác Lưu trữ
API endpoints mới với key tự sinh và tìm kiếm thông minh

Thao tác LƯU (SET) - Key tự sinh
POST

Endpoint: /api/storage/set

Dữ liệu gửi:

{
  "data": {
    "name": "Nguyễn Văn A",
    "age": 25,
    "skills": ["JavaScript", "Python"],
    "address": {
      "city": "Hà Nội",
      "district": "Cầu Giấy"
    }
  },
  "ttl": 3600 // tùy chọn
}

Phản hồi:

{
  "success": true,
  "message": "Lưu dữ liệu thành công",
  "data": {
    "key": "1a2b3c4d_ef567890abcdef12", // Key tự sinh
    "data": { ... }, // Dữ liệu gốc
    "createdAt": "2024-01-01T00:00:00.000Z"
  }
}

Thao tác TÌM KIẾM (SEARCH) - Theo nội dung
POST

Endpoint: /api/storage/search

Dữ liệu gửi:

// Tìm chính xác
{
  "data": {"name": "Nguyễn Văn A"}
}

// Tìm một phần
{
  "data": "JavaScript"
}

// Tìm số
{
  "data": 25
}

Phản hồi:

{
  "success": true,
  "data": {
    "searchQuery": "JavaScript",
    "results": [
      {
        "key": "1a2b3c4d_ef567890abcdef12",
        "data": { ... },
        "createdAt": "...",
        "updatedAt": "..."
      }
    ],
    "count": 1
  },
  "message": "Tìm thấy 1 kết quả"
}

Thao tác XÓA (DELETE) - Theo key
POST

Endpoint: /api/storage/delete

Dữ liệu gửi:

{
  "key": "1a2b3c4d_ef567890abcdef12" // Key từ kết quả tìm kiếm
}

Thao tác LẤY TẤT CẢ (ALL)
POST

Endpoint: /api/storage/all

Dữ liệu gửi:

{}
Ví dụ Sử dụng
Workflow hoàn chỉnh với key tự sinh và tìm kiếm

1. Lưu dữ liệu (Key tự sinh):

const userData = {
  name: "Nguyễn Văn A",
  age: 25,
  skills: ["JavaScript", "Python", "Go"],
  address: {
    city: "Hà Nội",
    district: "Cầu Giấy"
  }
};

// Lưu dữ liệu - key sẽ tự sinh
const response = await fetch('/api/storage/set', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your-api-key'
  },
  body: JSON.stringify({
    data: userData
  })
});

const result = await response.json();
console.log('Key tự sinh:', result.data.key);
// Output: Key tự sinh: 1a2b3c4d_ef567890abcdef12

2. Tìm kiếm theo nội dung:

// Tìm theo tên
const searchResponse = await fetch('/api/storage/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your-api-key'
  },
  body: JSON.stringify({
    data: "Nguyễn Văn A"
  })
});

const searchResult = await searchResponse.json();
console.log('Tìm thấy:', searchResult.data.count, 'kết quả');
console.log('Keys:', searchResult.data.results.map(r => r.key));

// Tìm theo skill
const skillSearch = await fetch('/api/storage/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your-api-key'
  },
  body: JSON.stringify({
    data: "JavaScript"
  })
});

3. Xóa theo key:

// Sử dụng key từ kết quả tìm kiếm
const keyToDelete = searchResult.data.results[0].key;

const deleteResponse = await fetch('/api/storage/delete', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your-api-key'
  },
  body: JSON.stringify({
    key: keyToDelete
  })
});

const deleteResult = await deleteResponse.json();
console.log('Đã xóa:', deleteResult.data.deleted);
VietStorage Pro API Documentation v3.0

Lưu trữ thông minh - Key tự sinh, tìm kiếm theo nội dung

Cập nhật lần cuối: 1/7/2025