rocket-net-api

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rocket.net API Integration

Rocket.net API集成

Build integrations with Rocket.net's managed WordPress hosting platform API. This skill covers authentication, site management, domain configuration, backups, plugins/themes, CDN cache control, and all 200+ API endpoints.
与Rocket.net的托管WordPress平台API进行集成开发。本技能涵盖身份验证、站点管理、域名配置、备份、插件/主题管理、CDN缓存控制以及全部200+个API端点。

API Overview

API概述

Base URL:
https://api.rocket.net/v1
Authentication: JWT token-based
  • Obtain token via POST
    /login
    with email/password
  • Token expires in 7 days
  • Include in requests as
    Authorization: Bearer <token>
Content Type: JSON API
  • Required header:
    Content-Type: application/json
  • Recommended header:
    Accept: application/json
基础URL
https://api.rocket.net/v1
身份验证:基于JWT令牌
  • 通过POST
    /login
    接口,使用邮箱/密码获取令牌
  • 令牌有效期为7天
  • 请求中需携带
    Authorization: Bearer <token>
内容类型:JSON API
  • 必填请求头:
    Content-Type: application/json
  • 推荐请求头:
    Accept: application/json

Authentication

身份验证

Get JWT Token

获取JWT令牌

typescript
const response = await fetch('https://api.rocket.net/v1/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  body: JSON.stringify({
    username: 'your-email@example.com',
    password: 'your-password'
  })
});

const { token } = await response.json();
// Use token in subsequent requests
typescript
const response = await fetch('https://api.rocket.net/v1/login', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  body: JSON.stringify({
    username: 'your-email@example.com',
    password: 'your-password'
  })
});

const { token } = await response.json();
// Use token in subsequent requests

Authenticated Request Pattern

已认证请求模板

typescript
async function rocketApiRequest(
  endpoint: string,
  options: RequestInit = {}
): Promise<any> {
  const response = await fetch(`https://api.rocket.net/v1${endpoint}`, {
    ...options,
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'Authorization': `Bearer ${token}`,
      ...options.headers
    }
  });

  if (response.status === 401) {
    // Token expired, re-authenticate
    throw new Error('Token expired - request new token');
  }

  return response.json();
}
typescript
async function rocketApiRequest(
  endpoint: string,
  options: RequestInit = {}
): Promise<any> {
  const response = await fetch(`https://api.rocket.net/v1${endpoint}`, {
    ...options,
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'Authorization': `Bearer ${token}`,
      ...options.headers
    }
  });

  if (response.status === 401) {
    // Token expired, re-authenticate
    throw new Error('Token expired - request new token');
  }

  return response.json();
}

API Endpoints by Category

按分类划分的API端点

Sites Management

站点管理

MethodEndpointDescription
GET
/sites
List all sites
POST
/sites
Create new site
GET
/sites/{id}
Get site details
PATCH
/sites/{id}
Update site properties
DELETE
/sites/{id}
Delete site
POST
/sites/{id}/clone
Clone a site (background task)
GET
/sites/{id}/credentials
Get site credentials
GET
/sites/{id}/usage
Get site usage statistics
POST
/sites/{id}/lock
Lock site (prevent modifications)
DELETE
/sites/{id}/lock
Unlock site
GET
/sites/{id}/pma_login
Get phpMyAdmin SSO link
GET
/sites/{id}/settings
Get site settings
PATCH
/sites/{id}/settings
Update site settings
GET
/sites/locations
List available site locations
请求方法端点描述
GET
/sites
列出所有站点
POST
/sites
创建新站点
GET
/sites/{id}
获取站点详情
PATCH
/sites/{id}
更新站点属性
DELETE
/sites/{id}
删除站点
POST
/sites/{id}/clone
克隆站点(后台任务)
GET
/sites/{id}/credentials
获取站点凭证
GET
/sites/{id}/usage
获取站点使用统计
POST
/sites/{id}/lock
锁定站点(阻止修改)
DELETE
/sites/{id}/lock
解锁站点
GET
/sites/{id}/pma_login
获取phpMyAdmin单点登录链接
GET
/sites/{id}/settings
获取站点设置
PATCH
/sites/{id}/settings
更新站点设置
GET
/sites/locations
列出可用站点部署位置

Staging Sites

staging站点(预发布站点)

MethodEndpointDescription
POST
/sites/{id}/staging
Create staging site
DELETE
/sites/{id}/staging
Delete staging site
POST
/sites/{id}/staging/publish
Publish staging to production
请求方法端点描述
POST
/sites/{id}/staging
创建预发布站点
DELETE
/sites/{id}/staging
删除预发布站点
POST
/sites/{id}/staging/publish
将预发布站点发布至生产环境

Site Templates

站点模板

MethodEndpointDescription
GET
/sites/templates
List site templates
POST
/sites/templates
Create site template
GET
/sites/templates/{id}
Get template details
DELETE
/sites/templates/{id}
Delete template
POST
/sites/templates/{id}/sites
Create site from template
请求方法端点描述
GET
/sites/templates
列出站点模板
POST
/sites/templates
创建站点模板
GET
/sites/templates/{id}
获取模板详情
DELETE
/sites/templates/{id}
删除模板
POST
/sites/templates/{id}/sites
通过模板创建站点

Domains

域名

MethodEndpointDescription
GET
/sites/{id}/domains
List domain aliases
POST
/sites/{id}/domains
Add domain alias
DELETE
/sites/{id}/domains/{domainId}
Remove domain alias
GET
/sites/{id}/maindomain
Get main domain info
POST
/sites/{id}/maindomain
Set main domain
PUT
/sites/{id}/maindomain
Replace main domain
PATCH
/sites/{id}/maindomain
Update domain validation/SSL
GET
/sites/{id}/maindomain/status
Check domain status
GET
/sites/{id}/maindomain/recheck
Force validation recheck
GET
/sites/{id}/domains/{domainId}/edge_settings
Get edge settings
PATCH
/sites/{id}/domains/{domainId}/edge_settings
Update edge settings
请求方法端点描述
GET
/sites/{id}/domains
列出域名别名
POST
/sites/{id}/domains
添加域名别名
DELETE
/sites/{id}/domains/{domainId}
移除域名别名
GET
/sites/{id}/maindomain
获取主域名信息
POST
/sites/{id}/maindomain
设置主域名
PUT
/sites/{id}/maindomain
替换主域名
PATCH
/sites/{id}/maindomain
更新域名验证/SSL配置
GET
/sites/{id}/maindomain/status
检查域名状态
GET
/sites/{id}/maindomain/recheck
强制重新验证域名
GET
/sites/{id}/domains/{domainId}/edge_settings
获取边缘节点设置
PATCH
/sites/{id}/domains/{domainId}/edge_settings
更新边缘节点设置

CDN Cache

CDN缓存

MethodEndpointDescription
POST
/sites/{id}/cache/purge
Purge specific files
POST
/sites/{id}/cache/purge_everything
Purge all cache
请求方法端点描述
POST
/sites/{id}/cache/purge
清除指定文件缓存
POST
/sites/{id}/cache/purge_everything
清除全部缓存

Plugins

插件

MethodEndpointDescription
GET
/sites/{id}/plugins
List installed plugins
POST
/sites/{id}/plugins
Install plugins
PATCH
/sites/{id}/plugins
Activate/deactivate plugins
PUT
/sites/{id}/plugins
Update plugins
DELETE
/sites/{id}/plugins
Delete plugins
GET
/sites/{id}/plugins/search
Search available plugins
GET
/sites/{id}/featured_plugins
List featured plugins
请求方法端点描述
GET
/sites/{id}/plugins
列出已安装插件
POST
/sites/{id}/plugins
安装插件
PATCH
/sites/{id}/plugins
启用/禁用插件
PUT
/sites/{id}/plugins
更新插件
DELETE
/sites/{id}/plugins
删除插件
GET
/sites/{id}/plugins/search
搜索可用插件
GET
/sites/{id}/featured_plugins
列出推荐插件

Themes

主题

MethodEndpointDescription
GET
/sites/{id}/themes
List installed themes
POST
/sites/{id}/themes
Install themes
PATCH
/sites/{id}/themes
Activate theme
PUT
/sites/{id}/themes
Update themes
DELETE
/sites/{id}/themes
Delete themes
GET
/sites/{id}/themes/search
Search available themes
请求方法端点描述
GET
/sites/{id}/themes
列出已安装主题
POST
/sites/{id}/themes
安装主题
PATCH
/sites/{id}/themes
启用主题
PUT
/sites/{id}/themes
更新主题
DELETE
/sites/{id}/themes
删除主题
GET
/sites/{id}/themes/search
搜索可用主题

Backups

备份

MethodEndpointDescription
GET
/sites/{id}/backup
List backups
POST
/sites/{id}/backup
Create backup
GET
/sites/{id}/backup/{backupId}
Download backup
DELETE
/sites/{id}/backup/{backupId}
Delete backup
POST
/sites/{id}/backup/{backupId}/restore
Restore backup
GET
/sites/{id}/backup/automated
List automated backups
POST
/sites/{id}/backup/automated/{restoreId}/restore
Restore automated backup
请求方法端点描述
GET
/sites/{id}/backup
列出备份
POST
/sites/{id}/backup
创建备份
GET
/sites/{id}/backup/{backupId}
下载备份
DELETE
/sites/{id}/backup/{backupId}
删除备份
POST
/sites/{id}/backup/{backupId}/restore
恢复备份
GET
/sites/{id}/backup/automated
列出自动备份
POST
/sites/{id}/backup/automated/{restoreId}/restore
恢复自动备份

Cloud Backups

云备份

MethodEndpointDescription
GET
/sites/{id}/cloud_backups
List cloud backups
POST
/sites/{id}/cloud_backups
Create cloud backup
GET
/sites/{id}/cloud_backups/{backupId}
Get cloud backup
DELETE
/sites/{id}/cloud_backups/{backupId}
Delete cloud backup
GET
/sites/{id}/cloud_backups/{backupId}/download
Get download link
POST
/sites/{id}/cloud_backups/{backupId}/restore
Restore cloud backup
请求方法端点描述
GET
/sites/{id}/cloud_backups
列出云备份
POST
/sites/{id}/cloud_backups
创建云备份
GET
/sites/{id}/cloud_backups/{backupId}
获取云备份详情
DELETE
/sites/{id}/cloud_backups/{backupId}
删除云备份
GET
/sites/{id}/cloud_backups/{backupId}/download
获取下载链接
POST
/sites/{id}/cloud_backups/{backupId}/restore
恢复云备份

Files

文件管理

MethodEndpointDescription
GET
/sites/{id}/file_manager/files
List files
POST
/sites/{id}/files
Upload file
PUT
/sites/{id}/files
Save file contents
DELETE
/sites/{id}/files
Delete file
GET
/sites/{id}/files/view
View file contents
GET
/sites/{id}/files/download
Download file
POST
/sites/{id}/files/folder
Create folder
POST
/sites/{id}/files/extract
Extract archive
POST
/sites/{id}/files/compress
Compress files
PATCH
/sites/{id}/files/chmod
Change permissions
请求方法端点描述
GET
/sites/{id}/file_manager/files
列出文件
POST
/sites/{id}/files
上传文件
PUT
/sites/{id}/files
保存文件内容
DELETE
/sites/{id}/files
删除文件
GET
/sites/{id}/files/view
查看文件内容
GET
/sites/{id}/files/download
下载文件
POST
/sites/{id}/files/folder
创建文件夹
POST
/sites/{id}/files/extract
解压归档文件
POST
/sites/{id}/files/compress
压缩文件
PATCH
/sites/{id}/files/chmod
修改文件权限

FTP Accounts

FTP账户

MethodEndpointDescription
GET
/sites/{id}/ftp_accounts
List FTP accounts
POST
/sites/{id}/ftp_accounts
Create FTP account
PATCH
/sites/{id}/ftp_accounts
Update FTP account
DELETE
/sites/{id}/ftp_accounts
Delete FTP account
请求方法端点描述
GET
/sites/{id}/ftp_accounts
列出FTP账户
POST
/sites/{id}/ftp_accounts
创建FTP账户
PATCH
/sites/{id}/ftp_accounts
更新FTP账户
DELETE
/sites/{id}/ftp_accounts
删除FTP账户

SSH Keys

SSH密钥

MethodEndpointDescription
GET
/sites/{id}/ssh_keys
List SSH keys
POST
/sites/{id}/ssh_keys
Import SSH key
DELETE
/sites/{id}/ssh_keys
Delete SSH key
POST
/sites/{id}/ssh_keys/authorize
Activate SSH key
POST
/sites/{id}/ssh_keys/deauthorize
Deactivate SSH key
GET
/sites/{id}/ssh_keys/{name}
View SSH key info
请求方法端点描述
GET
/sites/{id}/ssh_keys
列出SSH密钥
POST
/sites/{id}/ssh_keys
导入SSH密钥
DELETE
/sites/{id}/ssh_keys
删除SSH密钥
POST
/sites/{id}/ssh_keys/authorize
激活SSH密钥
POST
/sites/{id}/ssh_keys/deauthorize
停用SSH密钥
GET
/sites/{id}/ssh_keys/{name}
查看SSH密钥信息

WordPress

WordPress

MethodEndpointDescription
GET
/sites/{id}/wp_login
Get WordPress SSO link
GET
/sites/{id}/wp_status
Get WordPress status
POST
/sites/{id}/wpcli
Execute WP-CLI command
请求方法端点描述
GET
/sites/{id}/wp_login
获取WordPress单点登录链接
GET
/sites/{id}/wp_status
获取WordPress状态
POST
/sites/{id}/wpcli
执行WP-CLI命令

Reporting

报表

MethodEndpointDescription
GET
/reporting/sites/{id}/cdn_requests
CDN requests report
GET
/reporting/sites/{id}/cdn_cache_status
Cache status report
GET
/reporting/sites/{id}/cdn_cache_content
Cache content report
GET
/reporting/sites/{id}/visitors
Visitors report
GET
/reporting/sites/{id}/waf_eventlist
WAF events list
GET
/reporting/sites/{id}/waf_events_source
WAF events by source
GET
/reporting/sites/{id}/waf_firewall_events
Firewall events
GET
/reporting/sites/{id}/bandwidth_usage
Bandwidth usage
GET
/reporting/sites/{id}/bandwidth_top_usage
Top bandwidth usage
GET
/sites/{id}/access_logs
Access logs
请求方法端点描述
GET
/reporting/sites/{id}/cdn_requests
CDN请求报表
GET
/reporting/sites/{id}/cdn_cache_status
缓存状态报表
GET
/reporting/sites/{id}/cdn_cache_content
缓存内容报表
GET
/reporting/sites/{id}/visitors
访客报表
GET
/reporting/sites/{id}/waf_eventlist
WAF事件列表
GET
/reporting/sites/{id}/waf_events_source
按来源划分的WAF事件
GET
/reporting/sites/{id}/waf_firewall_events
防火墙事件
GET
/reporting/sites/{id}/bandwidth_usage
带宽使用报表
GET
/reporting/sites/{id}/bandwidth_top_usage
带宽Top使用报表
GET
/sites/{id}/access_logs
访问日志

Account Management

账户管理

MethodEndpointDescription
GET
/account/me
Get user information
PATCH
/account/me
Update account settings
GET
/account/usage
Get account usage stats
POST
/account/password
Change password
GET
/account/tasks
List account tasks
GET
/account/hosting_plan
Get current plan
PUT
/account/hosting_plan
Change hosting plan
POST
/account/billing_sso
Get billing SSO cookie
请求方法端点描述
GET
/account/me
获取用户信息
PATCH
/account/me
更新账户设置
GET
/account/usage
获取账户使用统计
POST
/account/password
修改密码
GET
/account/tasks
列出账户任务
GET
/account/hosting_plan
获取当前套餐
PUT
/account/hosting_plan
更换托管套餐
POST
/account/billing_sso
获取账单系统单点登录Cookie

Account Users

账户用户

MethodEndpointDescription
GET
/users
List account users
POST
/users
Create account user
GET
/users/{userId}
Get user details
PATCH
/users/{userId}
Update user
DELETE
/users/{userId}
Remove user
POST
/users/{userId}/reinvite
Resend invite
请求方法端点描述
GET
/users
列出账户用户
POST
/users
创建账户用户
GET
/users/{userId}
获取用户详情
PATCH
/users/{userId}
更新用户信息
DELETE
/users/{userId}
删除用户
POST
/users/{userId}/reinvite
重新发送邀请

Site Users

站点用户

MethodEndpointDescription
GET
/sites/{id}/users
List site users
POST
/sites/{id}/users
Invite site user
DELETE
/sites/{id}/users/{userId}
Remove site user
POST
/sites/{id}/users/{userId}/reinvite
Resend invite
请求方法端点描述
GET
/sites/{id}/users
列出站点用户
POST
/sites/{id}/users
邀请站点用户
DELETE
/sites/{id}/users/{userId}
删除站点用户
POST
/sites/{id}/users/{userId}/reinvite
重新发送邀请

Billing

账单

MethodEndpointDescription
GET
/billing/addresses
List billing addresses
POST
/billing/addresses
Create billing address
GET
/billing/addresses/{addressId}
Get billing address
PATCH
/billing/addresses/{addressId}
Update billing address
DELETE
/billing/addresses/{addressId}
Delete billing address
GET
/billing/invoices
List invoices
GET
/billing/invoices/{invoiceId}
Get invoice
GET
/billing/invoices/{invoiceId}/pdf
Download invoice PDF
POST
/billing/invoices/{invoiceId}/credit_card_payment
Pay with card
GET
/billing/payment_methods
List payment methods
POST
/billing/payment_methods
Add payment method
DELETE
/billing/payment_methods/{methodId}
Delete payment method
GET
/billing/products
List available products
请求方法端点描述
GET
/billing/addresses
列出账单地址
POST
/billing/addresses
创建账单地址
GET
/billing/addresses/{addressId}
获取账单地址详情
PATCH
/billing/addresses/{addressId}
更新账单地址
DELETE
/billing/addresses/{addressId}
删除账单地址
GET
/billing/invoices
列出发票
GET
/billing/invoices/{invoiceId}
获取发票详情
GET
/billing/invoices/{invoiceId}/pdf
下载发票PDF
POST
/billing/invoices/{invoiceId}/credit_card_payment
信用卡支付
GET
/billing/payment_methods
列出支付方式
POST
/billing/payment_methods
添加支付方式
DELETE
/billing/payment_methods/{methodId}
删除支付方式
GET
/billing/products
列出可用产品

Additional Features

附加功能

MethodEndpointDescription
GET
/sites/{id}/password_protection
Get password protection status
POST
/sites/{id}/password_protection
Enable password protection
DELETE
/sites/{id}/password_protection
Disable password protection
GET
/sites/{id}/shopshield
List ShopShield URIs
POST
/sites/{id}/shopshield
Enable ShopShield
DELETE
/sites/{id}/shopshield/{id}
Disable ShopShield
GET
/account/visitors
Account visitor stats
GET
/account/bandwidth
Account bandwidth stats
请求方法端点描述
GET
/sites/{id}/password_protection
获取密码保护状态
POST
/sites/{id}/password_protection
启用密码保护
DELETE
/sites/{id}/password_protection
禁用密码保护
GET
/sites/{id}/shopshield
列出ShopShield URI
POST
/sites/{id}/shopshield
启用ShopShield
DELETE
/sites/{id}/shopshield/{id}
禁用ShopShield
GET
/account/visitors
账户访客统计
GET
/account/bandwidth
账户带宽统计

Common Patterns

常见使用示例

List All Sites

列出所有站点

typescript
const sites = await rocketApiRequest('/sites');
console.log(sites);
// Returns array of site objects with id, domain, status, etc.
typescript
const sites = await rocketApiRequest('/sites');
console.log(sites);
// Returns array of site objects with id, domain, status, etc.

Create a New Site

创建新站点

typescript
const newSite = await rocketApiRequest('/sites', {
  method: 'POST',
  body: JSON.stringify({
    name: 'my-new-site',
    location: 'us-east-1',
    // Additional options as needed
  })
});
typescript
const newSite = await rocketApiRequest('/sites', {
  method: 'POST',
  body: JSON.stringify({
    name: 'my-new-site',
    location: 'us-east-1',
    // Additional options as needed
  })
});

Purge CDN Cache

清除CDN缓存

typescript
// Purge specific URLs
await rocketApiRequest(`/sites/${siteId}/cache/purge`, {
  method: 'POST',
  body: JSON.stringify({
    files: [
      'https://example.com/style.css',
      'https://example.com/script.js'
    ]
  })
});

// Purge everything
await rocketApiRequest(`/sites/${siteId}/cache/purge_everything`, {
  method: 'POST'
});
typescript
// Purge specific URLs
await rocketApiRequest(`/sites/${siteId}/cache/purge`, {
  method: 'POST',
  body: JSON.stringify({
    files: [
      'https://example.com/style.css',
      'https://example.com/script.js'
    ]
  })
});

// Purge everything
await rocketApiRequest(`/sites/${siteId}/cache/purge_everything`, {
  method: 'POST'
});

Create and Restore Backup

创建并恢复备份

typescript
// Create backup
const backup = await rocketApiRequest(`/sites/${siteId}/backup`, {
  method: 'POST'
});

// List backups
const backups = await rocketApiRequest(`/sites/${siteId}/backup`);

// Restore backup (background task)
await rocketApiRequest(`/sites/${siteId}/backup/${backupId}/restore`, {
  method: 'POST'
});
typescript
// Create backup
const backup = await rocketApiRequest(`/sites/${siteId}/backup`, {
  method: 'POST'
});

// List backups
const backups = await rocketApiRequest(`/sites/${siteId}/backup`);

// Restore backup (background task)
await rocketApiRequest(`/sites/${siteId}/backup/${backupId}/restore`, {
  method: 'POST'
});

Manage Plugins

管理插件

typescript
// List installed plugins
const plugins = await rocketApiRequest(`/sites/${siteId}/plugins`);

// Install plugin
await rocketApiRequest(`/sites/${siteId}/plugins`, {
  method: 'POST',
  body: JSON.stringify({
    plugins: ['wordfence', 'yoast-seo']
  })
});

// Update all plugins
await rocketApiRequest(`/sites/${siteId}/plugins`, {
  method: 'PUT',
  body: JSON.stringify({
    plugins: ['all']
  })
});

// Activate/deactivate plugin
await rocketApiRequest(`/sites/${siteId}/plugins`, {
  method: 'PATCH',
  body: JSON.stringify({
    plugins: ['wordfence'],
    action: 'activate' // or 'deactivate'
  })
});
typescript
// List installed plugins
const plugins = await rocketApiRequest(`/sites/${siteId}/plugins`);

// Install plugin
await rocketApiRequest(`/sites/${siteId}/plugins`, {
  method: 'POST',
  body: JSON.stringify({
    plugins: ['wordfence', 'yoast-seo']
  })
});

// Update all plugins
await rocketApiRequest(`/sites/${siteId}/plugins`, {
  method: 'PUT',
  body: JSON.stringify({
    plugins: ['all']
  })
});

// Activate/deactivate plugin
await rocketApiRequest(`/sites/${siteId}/plugins`, {
  method: 'PATCH',
  body: JSON.stringify({
    plugins: ['wordfence'],
    action: 'activate' // or 'deactivate'
  })
});

Execute WP-CLI Commands

执行WP-CLI命令

typescript
const result = await rocketApiRequest(`/sites/${siteId}/wpcli`, {
  method: 'POST',
  body: JSON.stringify({
    command: 'user list --format=json'
  })
});
typescript
const result = await rocketApiRequest(`/sites/${siteId}/wpcli`, {
  method: 'POST',
  body: JSON.stringify({
    command: 'user list --format=json'
  })
});

WordPress SSO Login

WordPress单点登录

typescript
// Get SSO link for WordPress admin
const { url } = await rocketApiRequest(`/sites/${siteId}/wp_login`);
// Redirect user to url for auto-login
typescript
// Get SSO link for WordPress admin
const { url } = await rocketApiRequest(`/sites/${siteId}/wp_login`);
// Redirect user to url for auto-login

TypeScript Types

TypeScript类型定义

typescript
interface RocketSite {
  id: number;
  name: string;
  domain: string;
  status: 'active' | 'suspended' | 'pending';
  location: string;
  created_at: string;
  updated_at: string;
}

interface RocketBackup {
  id: number;
  site_id: number;
  type: 'manual' | 'automated' | 'cloud';
  status: 'pending' | 'completed' | 'failed';
  size: number;
  created_at: string;
}

interface RocketPlugin {
  name: string;
  slug: string;
  version: string;
  status: 'active' | 'inactive';
  update_available: boolean;
}

interface RocketDomain {
  id: number;
  domain: string;
  is_main: boolean;
  ssl_status: 'pending' | 'active' | 'failed';
  validation_method: 'dns' | 'http';
}

interface RocketAuthResponse {
  token: string;
  expires_at: string;
}
typescript
interface RocketSite {
  id: number;
  name: string;
  domain: string;
  status: 'active' | 'suspended' | 'pending';
  location: string;
  created_at: string;
  updated_at: string;
}

interface RocketBackup {
  id: number;
  site_id: number;
  type: 'manual' | 'automated' | 'cloud';
  status: 'pending' | 'completed' | 'failed';
  size: number;
  created_at: string;
}

interface RocketPlugin {
  name: string;
  slug: string;
  version: string;
  status: 'active' | 'inactive';
  update_available: boolean;
}

interface RocketDomain {
  id: number;
  domain: string;
  is_main: boolean;
  ssl_status: 'pending' | 'active' | 'failed';
  validation_method: 'dns' | 'http';
}

interface RocketAuthResponse {
  token: string;
  expires_at: string;
}

Error Handling

错误处理

typescript
interface RocketApiError {
  error: string;
  message: string;
  status: number;
}

async function handleRocketRequest(endpoint: string, options?: RequestInit) {
  try {
    const response = await rocketApiRequest(endpoint, options);
    return { data: response, error: null };
  } catch (error) {
    if (error.status === 401) {
      // Re-authenticate and retry
      await refreshToken();
      return handleRocketRequest(endpoint, options);
    }
    if (error.status === 404) {
      return { data: null, error: 'Resource not found' };
    }
    if (error.status === 429) {
      // Rate limited - wait and retry
      await sleep(1000);
      return handleRocketRequest(endpoint, options);
    }
    return { data: null, error: error.message };
  }
}
typescript
interface RocketApiError {
  error: string;
  message: string;
  status: number;
}

async function handleRocketRequest(endpoint: string, options?: RequestInit) {
  try {
    const response = await rocketApiRequest(endpoint, options);
    return { data: response, error: null };
  } catch (error) {
    if (error.status === 401) {
      // Re-authenticate and retry
      await refreshToken();
      return handleRocketRequest(endpoint, options);
    }
    if (error.status === 404) {
      return { data: null, error: 'Resource not found' };
    }
    if (error.status === 429) {
      // Rate limited - wait and retry
      await sleep(1000);
      return handleRocketRequest(endpoint, options);
    }
    return { data: null, error: error.message };
  }
}

Background Tasks

后台任务

Many operations (clone, backup restore, staging publish) run as background tasks. Monitor task status:
typescript
// Start a background task
const { task_id } = await rocketApiRequest(`/sites/${siteId}/clone`, {
  method: 'POST',
  body: JSON.stringify({ name: 'cloned-site' })
});

// Check task status
const tasks = await rocketApiRequest(`/sites/${siteId}/tasks`);
const task = tasks.find(t => t.id === task_id);
console.log(task.status); // 'pending', 'running', 'completed', 'failed'

// Cancel task if needed
await rocketApiRequest(`/sites/${siteId}/tasks/${task_id}/cancel`, {
  method: 'POST'
});
许多操作(克隆站点、恢复备份、预发布站点发布)以后台任务形式运行。可通过以下方式监控任务状态:
typescript
// Start a background task
const { task_id } = await rocketApiRequest(`/sites/${siteId}/clone`, {
  method: 'POST',
  body: JSON.stringify({ name: 'cloned-site' })
});

// Check task status
const tasks = await rocketApiRequest(`/sites/${siteId}/tasks`);
const task = tasks.find(t => t.id === task_id);
console.log(task.status); // 'pending', 'running', 'completed', 'failed'

// Cancel task if needed
await rocketApiRequest(`/sites/${siteId}/tasks/${task_id}/cancel`, {
  method: 'POST'
});

Rate Limits

请求频率限制

The API has rate limits. Implement exponential backoff:
typescript
async function withRetry<T>(
  fn: () => Promise<T>,
  maxRetries = 3,
  delay = 1000
): Promise<T> {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (error.status === 429 && i < maxRetries - 1) {
        await new Promise(resolve => setTimeout(resolve, delay * Math.pow(2, i)));
        continue;
      }
      throw error;
    }
  }
  throw new Error('Max retries exceeded');
}
API设有请求频率限制,建议实现指数退避策略:
typescript
async function withRetry<T>(
  fn: () => Promise<T>,
  maxRetries = 3,
  delay = 1000
): Promise<T> {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (error.status === 429 && i < maxRetries - 1) {
        await new Promise(resolve => setTimeout(resolve, delay * Math.pow(2, i)));
        continue;
      }
      throw error;
    }
  }
  throw new Error('Max retries exceeded');
}

References

参考链接