A minimal, dependency-free REST API framework in PHP. It maps URLs like
/[resource]/[id] to a controller class and returns a consistent JSON
envelope, without requiring any external packages.
This is a small, educational framework — a good starting point for a lightweight PHP API, not a production-grade framework like Laravel/Symfony.
-
index.phpis the single front controller. Every request is rewritten to it (seenginx-config.txt/.htaccess). -
The first URL segment is mapped to
{Segment}Controllerand autoloaded fromcontrollers/(falling back tomodels/for framework classes). -
The HTTP method (
get,post,put,delete) is called on that controller with aRequestobject. -
The return value is wrapped in a JSON envelope by
ResponseJson:{ "success": true, "request": { "method": "GET", "controller": "platform", "resource": "countries", "...": "..." }, "error": { "errorid": 0, "message": null }, "data": [ { "...": "..." } ] }
- PHP 7.4+ (uses
mysqli) - MySQL/MariaDB
- nginx or Apache
Run the interactive installer from the project root:
./install.sh
It checks prerequisites, configures config.php, imports countries.sql,
and (optionally) writes and enables an nginx or Apache vhost for you. It
never overwrites files or reloads a web server without asking first.
- Deploy the files to your web server.
- Import
countries.sqlinto your database. - Edit
config.phpand provide your database credentials. - Point your web server rewrite rules at
index.php:- nginx: see
nginx-config.txt - Apache:
.htaccessis included
- nginx: see
GET /platform/countries -> all published countries
GET /platform/countries/1 -> country with id 1
GET /platform/currencies -> all currencies
Create a class in controllers/ extending AbstractController and
implement get/post/put/delete:
class WidgetsController extends AbstractController {
public function get($request) {
return array('widgets' => array());
}
public function post($request) { return $this->error('Not implemented'); }
public function put($request) { return $this->error('Not implemented'); }
public function delete($request) { return $this->error('Not implemented'); }
}Requests to /widgets will now be routed to it. Override
AbstractController::authorize() to add API key/token checks.
index.php Front controller / router
controllers/ Your API controllers
models/ Framework request/response classes
library/classes/Beep.php Database connection helper
library/classes/Country.php Sample data-access class used by PlatformController
countries.sql Sample dataset for the /platform/countries endpoint
tests/ PHPUnit test suite
composer install
composer test
CI runs the same suite (plus php -l linting) against PHP 7.4, 8.1 and 8.3
on every push and pull request.
Contributions are welcome - see CONTRIBUTING.md for how to get set up and run the checks locally. Please also review the Code of Conduct.
See CHANGELOG.md for release history.
MIT, see LICENSE.