Thiết lập Lưu trữ Đám mây JSON với jsonstore.io

Giải pháp lưu trữ dữ liệu cho dự án nhỏ

jsonstore.io cung cấp dịch vụ lưu trữ JSON trên đám mây với các ưu điểm:

  • Không yêu cầu máy chủ riêng
  • Thiết lập trong 2 giây
  • Hỗ trợ đầy đủ thao tác CRUD

So sánh giải pháp lưu trữ

Tính năngjsonstore.ioFirebaseMáy chủ tự quản
Độ phức tạpThấpTrung bìnhCao
Chi phíMiễn phíCó hạn mứcTùy cấu hình

Hướng dẫn thực hành

1. Nhận mã truy cập

// Tạo mã truy cập
fetch('https://www.jsonstore.io/get-token')
  .then(res => res.json())
  .then(data => console.log('Mã truy cập:', data.token));

2. Thao tác dữ liệu cơ bản

# Tạo dữ liệu
curl -X POST "https://www.jsonstore.io/TOKEN/nguoidung/1" \
  -H "Content-Type: application/json" \
  -d '{"ten":"Minh","tuoi":28}'

3. Truy vấn nâng cao

// Lọc dữ liệu theo điều kiện
async function locNguoiDung(tuoi) {
  const res = await fetch(
    `https://www.jsonstore.io/TOKEN/nguoidung?orderKey=tuoi&filterValue=${tuoi}`
  );
  return res.json();
}

Ví dụ ứng dụng

Lớp client JavaScript

class JsonClient {
  constructor(token) {
    this.baseUrl = `https://www.jsonstore.io/${token}`;
  }
  
  async taoDuongDan(duongDan, duLieu) {
    return fetch(`${this.baseUrl}/${duongDan}`, {
      method: 'POST',
      body: JSON.stringify(duLieu)
    });
  }
}

const client = new JsonClient('TOKEN');
client.taoDuongDan('sanpham', {id: 101, ten: 'Laptop'});

Ứng dụng React

function DanhSachSP() {
  const [sanPham, setSanPham] = useState([]);
  
  useEffect(() => {
    fetch('https://www.jsonstore.io/TOKEN/sanpham')
      .then(res => res.json())
      .then(data => setSanPham(data.result));
  }, []);
  
  return (
    <ul>
      {Object.values(sanPham).map(sp => (
        <li key={sp.id}>{sp.ten}</li>
      ))}
    </ul>
  );
}

Tích hợp Python

import requests

class JsonPythonClient:
    def __init__(self, token):
        self.base_url = f"https://www.jsonstore.io/{token}"
    
    def docDuLieu(self, duongDan):
        return requests.get(f"{self.base_url}/{duongDan}").json()

client = JsonPythonClient("TOKEN")
danhSach = client.docDuLieu("donhang")
print(danhSach)

Triển khai tự quản

git clone https://github.com/js/jsonstore.git
cd jsonstore
npm install
export FIREBASE_CONFIG='{...}'
npm run server:start

Thẻ: jsonstore.io JSON lưu trữ đám mây CRUD API RESTful

Đăng vào ngày 22 tháng 7 lúc 02:29