> ## Documentation Index
> Fetch the complete documentation index at: https://docs.x.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API Playground

> ローカルのモックサーバーで X API v2 のエンドポイントを開発中にテストできます。API クレジットを消費せずに、リクエスト例やレスポンスペイロードも確認できます。

[API Playground](https://github.com/xdevplatform/playground) は、X API v2 の全体をシミュレートするローカルのモックサーバーです。実際の API クレジットを消費せずに、エンドポイントをテストし、プロトタイプを作成し、API を試すことができます。

<Card title="GitHub リポジトリ" icon="github" href="https://github.com/xdevplatform/playground">
  ソースコード、リリース、完全なドキュメント。
</Card>

***

## 機能

<CardGroup cols={2}>
  <Card title="API v2 との完全な互換性" icon="check">
    OpenAPI 仕様によるリクエスト検証と現実的なエラーレスポンスにより、すべてのエンドポイントをサポート。
  </Card>

  <Card title="インタラクティブな Web UI" icon="browser">
    `http://localhost:8080/playground` のビジュアルエンドポイントエクスプローラーで、ブラウザ上からテスト可能。
  </Card>

  <Card title="クレジット不要" icon="https://mintcdn.com/x-preview/ygI6sSJPehlc0qNT/icons/xds/icon-coins.svg?fit=max&auto=format&n=ygI6sSJPehlc0qNT&q=85&s=d8b17de3fb4032d86b77606ea95fcb55" width="24" height="24" data-path="icons/xds/icon-coins.svg">
    すべてモックデータでローカルに動作 — API キーや請求は不要。
  </Card>

  <Card title="状態を持つ操作" icon="database">
    ファイル永続化(任意)を備えたインメモリの状態管理。投稿を作成し、その後ルックアップできます。
  </Card>
</CardGroup>

***

## インストール

Go 1.21+ が必要です。ソースからインストールするか、[releases](https://github.com/xdevplatform/playground/releases) から事前ビルド済みのバイナリをダウンロードしてください。

<Tabs>
  <Tab title="Go install">
    ```bash theme={null}
    go install github.com/xdevplatform/playground/cmd/playground@latest
    playground start
    ```
  </Tab>

  <Tab title="ソースからビルド">
    ```bash theme={null}
    git clone https://github.com/xdevplatform/playground.git
    cd playground
    go build -o playground ./cmd/playground
    ./playground start
    ```
  </Tab>
</Tabs>

サーバーはデフォルトで `http://localhost:8080` で起動します。

***

## クイックスタート

実際の API と同じようにリクエストを送信できます。Bearer Token には `test_token` を使用します。

```bash title="me" lines wrap icon="terminal" theme={null}
# Look up a user
curl -H "Authorization: Bearer test_token" \
  http://localhost:8080/2/users/me

# Create a post
curl -X POST -H "Authorization: Bearer test_token" \
  -H "Content-Type: application/json" \
  -d '{"text": "Hello from the playground!"}' \
  http://localhost:8080/2/tweets

# Search posts
curl -H "Authorization: Bearer test_token" \
  "http://localhost:8080/2/tweets/search/recent?query=hello"
```

ブラウザで `http://localhost:8080/playground` を開くとインタラクティブ UI を利用できます。

***

## 含まれているもの

| 機能            | 説明                            |
| :------------ | :---------------------------- |
| **リクエスト検証**   | OpenAPI 仕様に対してリクエストを検証        |
| **現実的なエラー**   | 適切なエラーコードとメッセージを返す            |
| **ストリーミング対応** | ストリーミングエンドポイントのシミュレーション       |
| **レート制限**     | 設定可能なレート制限シミュレーション            |
| **CORS 対応**   | ブラウザベースのアプリケーションでも動作          |
| **使用状況の追跡**   | 請求とクレジット追跡エンドポイントのシミュレーション    |
| **状態の永続化**    | 任意で `~/.playground/` にファイル永続化 |

***

## 関連情報

<CardGroup cols={2}>
  <Card title="xurl" icon="terminal" href="/tools/xurl">
    認証を内蔵した、実際の X API 用の CLI ツール。
  </Card>

  <Card title="初めてのリクエストを送る" icon="https://mintcdn.com/x-preview/oR-aRNyj1BKPJtxM/icons/xds/icon-rocket.svg?fit=max&auto=format&n=oR-aRNyj1BKPJtxM&q=85&s=b978d7a9225de31709efbbed5b84e92d" href="/make-your-first-request" width="24" height="24" data-path="icons/xds/icon-rocket.svg">
    本物の API を試す準備ができたら、最初のリクエストを送りましょう。
  </Card>
</CardGroup>
