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
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 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
Chỉ cần gửi dữ liệu - mọi thứ khác được xử lý tự động
X-API-Key: your-api-key-hereEndpoint: /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"
}
}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ả"
}Endpoint: /api/storage/delete
Dữ liệu gửi:
{
"key": "1a2b3c4d_ef567890abcdef12" // Key từ kết quả tìm kiếm
}Endpoint: /api/storage/all
Dữ liệu gửi:
{}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// 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"
})
});// 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);Lưu trữ thông minh - Key tự sinh, tìm kiếm theo nội dung