轻量级 JSON 存储服务

专为静态站点设计的数据存储 API,无需复杂后端开发,几行代码即可让您的静态站点具备数据存储能力

API 概览

简单易用的 RESTful API,支持创建、读取、更新 JSON 数据

健康检查

GET /health

检查服务状态

生成 GUID

GET /guid

获取唯一标识符

读取数据

GET /get

根据 GUID 读取数据

创建/更新

PUT /update

保存或更新数据

快速开始

3 分钟上手 FastData API

1

引入依赖

<!-- 引入 CryptoJS 用于 token 生成 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
2

创建客户端

class FastDataClient {
    constructor(ownerKey) {
        this.ownerKey = ownerKey;
        this.token = this.generateToken(ownerKey);
        this.baseUrl = 'https://fastdata.qiangtu.com';
    }

    generateToken(ownerKey) {
        const input = `fastdata_salt_${ownerKey}`;
        const hash = CryptoJS.SHA256(input).toString();
        return hash.substring(0, 16).toLowerCase();
    }
    
    // ... 其他方法
}
3

开始使用

// 创建客户端实例
const client = new FastDataClient('my_website');

// 创建数据
const guid = await client.create({
    title: '我的文章',
    content: '这是文章内容',
    author: '张三'
});

// 读取数据
const data = await client.get(guid);
console.log(data);
4

更新数据

// 更新数据
data.title = '更新后的标题';
await client.save(guid, data);

// 获取新的 GUID
const newGuid = await client.getGuid();

使用示例

常见场景的完整实现

博客系统

创建一个简单的博客系统,支持文章发布和管理

功能特性

  • 文章发布和编辑
  • 文章列表管理
  • 作者信息记录
  • 创建时间跟踪

核心代码

class BlogManager {
    constructor() {
        this.client = new FastDataClient('my_blog');
        this.postsListGuid = 'blog_posts_list';
    }

    async createPost(title, content, author) {
        const post = {
            title, content, author,
            createdAt: new Date().toISOString(),
            id: await this.client.getGuid()
        };
        
        await this.client.save(post.id, post);
        
        const posts = await this.getPostsList();
        posts.push(post);
        await this.client.save(this.postsListGuid, posts);
        
        return post;
    }
    
    async getPostsList() {
        try {
            return await this.client.get(this.postsListGuid) || [];
        } catch {
            return [];
        }
    }
}

评论系统

为文章添加评论功能,支持多级评论

功能特性

  • 匿名评论支持
  • 评论时间记录
  • 按文章分组管理
  • 评论数量统计

核心代码

class CommentManager {
    constructor(postId) {
        this.client = new FastDataClient('my_blog');
        this.postId = postId;
        this.commentsGuid = `comments_${postId}`;
    }

    async addComment(name, content) {
        const comment = {
            id: await this.client.getGuid(),
            name, content,
            createdAt: new Date().toISOString()
        };

        const comments = await this.getComments();
        comments.push(comment);
        await this.client.save(this.commentsGuid, comments);
        
        return comment;
    }
    
    async getComments() {
        try {
            return await this.client.get(this.commentsGuid) || [];
        } catch {
            return [];
        }
    }
}

在线测试

直接在浏览器中测试 API 功能

API 测试面板

测试结果

{{ testStatus.message }}

响应数据

{{ testResult || '暂无数据' }}

生成的 GUID

测试历史

{{ item.action }}
{{ item.time }}