0.1.0 • Published 5 months ago
next-json-server v0.1.0
Next JSON Server
Next.js App Router ベースの軽量な JSON Server 実装です。json-serverにインスパイアされており、シンプルな RESTful API を JSON file ベースで提供します。
特徴
- 💡 Next.js App Router 対応
- 🚀 シンプルなセットアップ
- 📝 JSON file ベースのデータ管理
- 🔄 完全な RESTful API サポート
- 🛠 カスタマイズ可能なエンドポイント
始め方
- パッケージをインストール
bun -v # or npm, yarn, pnpm
bun i
- プロジェクトのルートに
db.json
を作成
{
"posts": [
{ "id": "1", "title": "a title", "views": 100 },
{ "id": "2", "title": "another title", "views": 200 }
],
"comments": [
{ "id": "1", "text": "a comment about post 1", "postsId": "1" },
{ "id": "2", "text": "another comment about post 1", "postsId": "1" }
],
"users": [{ "id": "1", "name": "yuyakinjo" }]
}
- サーバーを起動
bun dev
API エンドポイント
以下の RESTful API エンドポイントが利用可能です:
リソースの取得
GET /json/posts
- 全ての投稿を取得GET /json/posts/1
- ID:1 の投稿を取得GET /json/comments
- 全てのコメントを取得GET /json/users
- 全てのユーザーを取得
リソースの作成
POST /json/posts
- 新しい投稿を作成
{
"title": "新しい投稿",
"views": 0
}
リソースの更新
PUT /json/posts/1
- ID:1 の投稿を更新
{
"title": "更新された投稿",
"views": 150
}
リソースの削除
DELETE /json/posts/1
- ID:1 の投稿を削除
レスポンス例
GET /json/posts
[
{
"id": "1",
"title": "a title",
"views": 100
},
{
"id": "2",
"title": "another title",
"views": 200
}
]
ステータスコード
200
- リクエスト成功201
- リソース作成成功204
- リソース削除成功404
- リソースが見つからない
開発環境での使用
- リポジトリをクローン
git clone https://github.com/yuyakinjo/next-json-server.git
- 依存関係をインストール
cd next-json-server
bun install
- 開発サーバーを起動
bun dev
Docker での実行
Docker を使用して実行することも可能です:
docker compose up -d
ライセンス
MIT ライセンスの下で公開されています。詳細についてはLICENSEを参照してください。
0.1.0
5 months ago