A small PHP API using PDO, a custom router, and MySQL. PHPUnit tests use an in-memory SQLite database and do not need a running MySQL server.
- PHP 8.2 or newer with
pdo_mysql,pdo_sqlite,mbstring, andopenssl - Composer 2
- MySQL for running the API
From this directory, install dependencies and create your local environment file:
composer install
Copy-Item .env.example .envCreate the database named in DB_NAME in .env, then set DB_HOST, DB_USERNAME, and DB_PASSWORD for your MySQL installation. Replace JWT_SECRET with a long, random value before using the API. Set STRIPE_SECRET_KEY to enable Stripe payments.
Run the migrations:
php cli/run_migrations.php migrateStart PHP's built-in server with the router script so API paths are forwarded to the application:
php -S 127.0.0.1:8000 -t public public/router.phpThe API is available at http://127.0.0.1:8000. Existing endpoints are:
| Method | Path | Purpose |
|---|---|---|
| POST | /register |
Create a user |
| POST | /login |
Authenticate a user |
| GET | /users |
List users |
| GET | /users/{id} |
Get a user |
| POST | /users |
Create a user |
| PUT | /users/{id} |
Update a user |
| DELETE | /users/{id} |
Delete a user |
| POST | /payment |
Process a Stripe payment |
| POST | /webhook |
Receive a Stripe event |
The user endpoints require an Authorization: Bearer <token> header from /login. Registration and login are public. Requests that create or update users accept JSON. For example:
{
"fullname": "Ada Lovelace",
"email": "ada@example.com",
"password": "use-a-strong-password"
}Install dependencies first, then run the test suite from this directory:
composer testThe tests use SQLite :memory: and require PHP's pdo_sqlite extension. They do not read .env or modify your MySQL database.
To run PHPUnit directly:
php vendor/phpunit/phpunit/phpunit --configuration phpunit.xmlphp cli/run_migrations.php migrate
php cli/run_migrations.php rollback