API Documentation

使用我们的API来程序化地创建和管理MiniApps

认证
所有API请求都需要使用API密钥进行认证

在请求头中包含你的API密钥:

X-API-Key: sk_your_api_key_here

或使用Bearer Token格式:

Authorization: Bearer sk_your_api_key_here
限流

默认限制:每小时100个请求

响应头会包含限流信息:

  • X-RateLimit-Limit - 限制数量
  • X-RateLimit-Remaining - 剩余请求数
  • X-RateLimit-Reset - 重置时间
创建MiniApp
POST/api/v1/miniapps

请求体:

{
  "name": "My MiniApp",
  "description": "一个简单的计数器应用",
  "sourceCode": "function App() { return <div>Hello World</div>; }\nReactDOM.render(<App />, document.getElementById('root'));",
  "isPublic": false,  // 可选,默认为false(私有)
  "autoGeneratePreview": true
}

示例请求(Node.js):

const response = await fetch('https://your-domain.com/api/v1/miniapps', {
  method: 'POST',
  headers: {
    'X-API-Key': 'sk_your_api_key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'My MiniApp',
    description: '一个简单的计数器应用',
    sourceCode: `function App() {
      const [count, setCount] = React.useState(0);
      return (
        <div className="p-4">
          <h1>计数器: {count}</h1>
          <button onClick={() => setCount(count + 1)}>+1</button>
        </div>
      );
    }
    ReactDOM.render(<App />, document.getElementById('root'));`,
    autoGeneratePreview: true
  })
});

const data = await response.json();
console.log('MiniApp URL:', data.data.url);

响应示例:

{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "shortId": "Ab3Cd5Ef",  // 8字符短链接ID
    "name": "My MiniApp",
    "description": "一个简单的计数器应用",
    "isPublic": false,
    "url": "https://your-domain.com/miniapps/Ab3Cd5Ef",  // 使用短链接
    "createdAt": "2024-01-01T00:00:00.000Z"
  },
  "message": "Miniapp created successfully"
}
错误处理

API使用标准HTTP状态码表示请求结果:

200 OK请求成功
201 Created资源创建成功
400 Bad Request请求参数错误
401 Unauthorized认证失败
403 Forbidden权限不足
404 Not Found资源不存在
429 Too Many Requests请求过于频繁
500 Internal Server Error服务器错误