PHPackages                             fuwasegu/dir-json-server - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fuwasegu/dir-json-server

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fuwasegu/dir-json-server
========================

Directory JSON Server

v1.0.0(1y ago)0122MITPHPPHP ^8.3

Since Sep 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/fuwasegu/dir-json-server)[ Packagist](https://packagist.org/packages/fuwasegu/dir-json-server)[ RSS](/packages/fuwasegu-dir-json-server/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Directory JSON Server
=====================

[](#directory-json-server)

静的なディレクトリ構造を JSON Server として公開するためのツールです． 返却したいレスポンスを JSON ファイルとして配置することで， その JSON ファイルを返却する API を簡単に公開することができます．

インストール
------

[](#インストール)

```
composer require --dev fuwasegu/dir-json-server

```

仕様
--

[](#仕様)

`contents/` に配置した JSON ファイルを API として公開します．ただし，ルートディレクトリは後述の yaml ファイルで変更可能です． 当該ディレクトリ直下が API のベースパスとなり，その直下に配置した JSON ファイルがそのままレスポンスとなります．

JSON ファイルは，必ず `response.json` という名前で配置してください．

本ツールは，GET のみをサポートしています．

利用例
---

[](#利用例)

コンテンツディレクトリを以下のように配置したとします．

```
contents/
  users/
    1/
      profile/
        response.json

```

また，`contents/users/1/profile/response.json` に以下のような JSON データが配置されていたとします．

```
{
  "id": 1,
  "name": "John Doe"
}

```

このとき，`GET http://localhost/users/1/profile` にアクセスすると，

```
{
  "id": 1,
  "name": "John Doe"
}

```

というレスポンスが返却されます．

つまり，

- contents/ をデフォルトのルートとしてその直下が URL のパスとなる
- レスポンスにしたいデータを response.json として配置する
- パスパラメータやクエリパラメータは利用できない
    - パスパラメータは，ディレクトリ名として配置することで実現できる

### レスポンス

[](#レスポンス)

レスポンスの ContentType について，

- デフォルトでは application/json となる
- ルートパスのみ，HTML が返されるため，この場合は text/html となる

サーバーの起動方法
---------

[](#サーバーの起動方法)

```
./dir-json serve

```

### 利用可能なルートの確認

[](#利用可能なルートの確認)

localhost:8000 にブラウザからアクセスすると，利用可能なルートの一覧が表示されます． こちらは，HTML で表示されます．

ルートは箇条書きに表示され，クリックすることでそのルートにアクセスすることができます．

### API レスポンス

[](#api-レスポンス)

基本的に，存在するディレクトリの末端に配置された JSON ファイルがそのままレスポンスとして返却されます． もし，ディレクトリの末端に配置された JSON ファイルが存在しない場合は，ステータスコード 404 が返却されます． また，このとき以下のような json が返却されます．

```
{
  "status": "error",
  "message": "File not found",
  "path": "contents/users/2/profile/response.json"
}

```

### デフォルトルートディレクトリとポートの設定変更

[](#デフォルトルートディレクトリとポートの設定変更)

デフォルトのルートディレクトリとポート番号は、`dir-json.yaml` ファイルで変更可能です。

```
root_path: 'contents'
port: 8000

```

設計
--

[](#設計)

### 採用技術

[](#採用技術)

- PHP 8.3
- Composer

### ディレクトリ構造

[](#ディレクトリ構造)

このプロジェクトは，以下のようなディレクトリ構造を持っています（一部省略）

```
root/
  contents/
  public/
    index.php
  src/
  composer.json

```

- contents/: コンテンツを配置するディレクトリ
- public/: 公開するディレクトリ. この中に index.php があり，エントリポイントとなります
- src/: サーバーのコードを配置するディレクトリ
- composer.json: 依存関係を管理するためのファイル

### 名前空間

[](#名前空間)

composer.json にて定義されている通り，src/ 配下のファイルは App\\ 名前空間配下に配置されます．

### アーキテクチャ

[](#アーキテクチャ)

このプロジェクトは基本的にクリーンアーキテクチャを採用しています．

本アプリケーションは，DB を使わない代わりに静的なディレクトリ構造を JSON Server として公開するため，インフラ層ではファイルアクセスを行います．

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

599d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e9d5d8ea70fe4695c076b8f0ac7143841b72ec88ea73fbb0cadf62992daecadb?d=identicon)[fuwasegu](/maintainers/fuwasegu)

---

Top Contributors

[![fuwasegu](https://avatars.githubusercontent.com/u/52437973?v=4)](https://github.com/fuwasegu "fuwasegu (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fuwasegu-dir-json-server/health.svg)

```
[![Health](https://phpackages.com/badges/fuwasegu-dir-json-server/health.svg)](https://phpackages.com/packages/fuwasegu-dir-json-server)
```

###  Alternatives

[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M157](/packages/orchestra-canvas)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
