Skip to content

Bukwid/phervon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phervon Logo

Phervon is a lightweight PHP-based JSON server inspired by JSON Server. It allows you to perform RESTful CRUD operations using a simple db.json file without any frameworks. Perfect for prototyping, mocking APIs, or lightweight persistence for local projects.


🚀 Features

  • ⚡️ Super simple REST API with PHP
  • 📦 No database required, just JSON files
  • 🛠 CRUD support: GET, POST, PUT, DELETE
  • 🔎 Query filtering by any key
  • 🧪 Schema validation per resource (optional via config.json)
  • 🔑 Auto-generated unique phervonId per entry
  • 📁 Configurable JSON file name via CLI or config
  • 💻 CLI tool to start server (bin/phervon)

📁 Project Structure

phervon/
├── bin/
│   └── phervon         # CLI entry
├── public/
│   └── index.php       # Web server entry point
├── src/
│   └── Server.php      # Core logic
├── db.json             # Default data file
├── config.json         # Optional schema/config
├── composer.json       # PSR-4 autoload config
└── README.md

⚙️ Installation

  1. Clone or download the repository:
git clone https://github.com/bukwid/phervon.git
cd phervon
  1. Install dependencies:
composer install
  1. Make CLI executable (on Unix):
chmod +x bin/phervon

🖥️ Usage

Start Server (Default)

php bin/phervon

With Options

php bin/phervon --file=mydata.json --port=8080

Show Help

php bin/phervon --help

🌐 API Endpoints

All endpoints follow the structure:

GET    /<resource>
GET    /<resource>/<phervonId>
POST   /<resource>
PUT    /<resource>/<phervonId>
DELETE /<resource>/<phervonId>

Example with posts resource

curl http://localhost:8000/posts
curl http://localhost:8000/posts/<phervonId>

curl -X POST http://localhost:8000/posts ^
     -H "Content-Type: application/json" ^
     -d "{\"title\":\"Hello\", \"body\":\"World\"}"

curl -X PUT http://localhost:8000/posts/<phervonId> ^
     -H "Content-Type: application/json" ^
     -d "{\"title\":\"Updated\"}"

curl -X DELETE http://localhost:8000/posts/<phervonId>

Query Filtering

curl http://localhost:8000/users?[email protected]

🧩 Schema Support

Add config.json in root to enforce required fields:

{
  "schema": {
    "posts": ["title", "body"],
    "users": ["name", "email"]
  }
}

If schema is defined, missing fields will result in a 400 Bad Request.


🧪 Example db.json

{
  "posts": [
      {
          "title": "Final Test Post",
          "body": "Testing before release",
          "phervonId": "a60e31262fc87cc077cfacca"
      }
  ],
  "users": [
      {
          "id": 2,
          "name": "Bob",
          "email": "[email protected]",
          "phervonId": "7911a24bf8143951764e20cd"
      }
  ]
}

⚠️ Notes for XAMPP Users

  • Move the index.php from the /public/ to the root directory if running in XAMPP.
  • But this is only an alternative that is only advisable in development and not for production for security purposes.

So better: use the built-in server via php bin/phervon instead.


📦 Roadmap / Todo

  • Add support for more Params(conditions, Range, Paginate)
  • Add logging for requests
  • Add CORS support
  • Allow nested resources (e.g., /posts/1/comments)
  • Include and auth feature(Password Hashing)
  • Add Docker support for deployment

📄 License

MIT License

Copyright (c) 2025 Kenneth Buquid

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


🙌 Credits

Built with ❤️ by Kenneth Leonard M. Buquid. Inspired by typicode/json-server, but fully in PHP!

About

Just like json-server but with php

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages