mcpField
R
remix-rest-snippets

remix-rest-snippets

github.com/farworld-labs开发59 次安装
代码仓库

关于 remix-rest-snippets

一组用于操作 Remix 游戏的 TypeScript REST API 示例,面向实现 API 调用的开发者,涵盖图像、精灵、商店物品、资源上传和游戏更新。

主要功能

  1. 01TypeScript REST 请求示例
  2. 02图像生成请求
  3. 03精灵生成请求
  4. 04商店物品的列出与创建
  5. 05资源上传与游戏更新

适用场景

  1. 01通过 API 生成游戏图像
  2. 02创建或列出商店物品
  3. 03上传游戏资源
  4. 04更新游戏信息

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/farworld-labs/remix-skills --skill remix-rest-snippets

安装后在 Claude Code 中输入/remix-rest-snippets确认已加载。

README 原文English

来自项目 README

README 暂无中文译文,以下为英文原文;中文介绍见上方。

TypeScript (REST)

const baseUrl = 'https://api.remix.gg'
const headers = {
  Authorization: `Bearer ${process.env.REMIX_API_KEY!}`,
  'Content-Type': 'application/json',
}

const openApiSpec = await fetch(`${baseUrl}/docs/json`, {
  method: 'GET',
  headers,
}).then((r) => r.json())

const createRes = await fetch(`${baseUrl}/v1/games`, {
  method: 'POST',
  headers,
  body: JSON.stringify({ name: 'Neon Dash' }),
})
const createJson = await createRes.json()
if (!createJson.success) throw new Error(createJson.error.message)

const gameId = createJson.data.game.id as string
const versionId = createJson.data.game.version.id as string

const updateRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/versions/${versionId}/code`,
  {
    method: 'POST',
    headers,
    body: JSON.stringify({ code: html }),
  },
)
const updateJson = await updateRes.json()
if (!updateJson.success) throw new Error(updateJson.error.message)

const validateRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/versions/${versionId}/validate`,
  { method: 'GET', headers },
)
const validateJson = await validateRes.json()
if (!validateJson.success) throw new Error(validateJson.error.message)
if (!validateJson.data.valid) {
  throw new Error(`Blocked: ${validateJson.data.blockers.map((b: { code: string }) => b.code).join(', ')}`)
}

const statusRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/versions/${versionId}/status`,
  { method: 'GET', headers },
)
const statusJson = await statusRes.json()
if (!statusJson.success) throw new Error(statusJson.error.message)

const readinessRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/launch-readiness?versionId=${versionId}`,
  { method: 'GET', headers },
)
const readinessJson = await readinessRes.json()
if (!readinessJson.success) throw new Error(readinessJson.error.message)

const leaderboardRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/analytics/leaderboard?startDate=2026-03-01&endDate=2026-03-15`,
  { method: 'GET', headers },
)
const leaderboardJson = await leaderboardRes.json()
if (!leaderboardJson.success) throw new Error(leaderboardJson.error.message)

Image Generation

const imageRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/images/generate`,
  {
    method: 'POST',
    headers,
    body: JSON.stringify({ prompt: 'A neon cityscape background' }),
  },
)
const imageJson = await imageRes.json()
if (!imageJson.success) throw new Error(imageJson.error.message)

Sprite Generation

const spriteRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/sprites/generate`,
  {
    method: 'POST',
    headers,
    body: JSON.stringify({ prompt: 'A pixel art character running' }),
  },
)
const spriteJson = await spriteRes.json()
if (!spriteJson.success) throw new Error(spriteJson.error.message)

Shop Items

// List items
const itemsRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/items`,
  { method: 'GET', headers },
)
const itemsJson = await itemsRes.json()

// Create item
const createItemRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/items`,
  {
    method: 'POST',
    headers,
    body: JSON.stringify({
      name: 'Speed Boost',
      slug: 'speed-boost',
      itemType: 'CONSUMABLE',
      bitsCost: 100,
    }),
  },
)
const createItemJson = await createItemRes.json()

// Delete item
const itemId = createItemJson.data.item.id
const deleteItemRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/items/${itemId}`,
  { method: 'DELETE', headers },
)

Asset Upload

const formData = new FormData()
formData.append('file', fileBlob, 'icon.png')

const assetRes = await fetch(
  `${baseUrl}/v1/games/${gameId}/assets`,
  {
    method: 'POST',
    headers: { Authorization: `Bearer ${process.env.REMIX_API_KEY!}` },
    body: formData,
  },
)
const assetJson = await assetRes.json()
if (!assetJson.success) throw new Error(assetJson.error.message)

Game Update

const gameUpdateRes = await fetch(
  `${baseUrl}/v1/games/${gameId}`,
  {
    method: 'POST',
    headers,
    body: JSON.stringify({ name: 'Neon Dash Deluxe' }),
  },
)
const gameUpdateJson = await gameUpdateRes.json()
if (!gameUpdateJson.success) throw new Error(gameUpdateJson.error.message)

评论

支持 Markdown