Sample REST API for working with two entities — articles and users, with authorization support.
This project uses the following basic environment setup:
- PHP 8.2 CLI with extensions:
bcmath
,sockets
,mysqli
- MySQL 8.0 database with user, password, and database name as defined in
docker-compose.yml
For detailed configuration, please see the Dockerfile
and docker-compose.yml
files.
If you are not running the project via Docker, you need to configure your environment to match these settings as closely as possible. This includes:
- Installing the required PHP version and extensions
- Setting up a MySQL 8.0 database
- Mounting or placing project files in the correct path
Additionally, you might need to adjust URLs or paths in tests to reflect your local environment if it differs from the Docker setup.
Keeping environments aligned ensures consistent behavior and successful test runs.
This project runs on the Nette Framework and uses the following key Composer packages:
Package | Purpose |
---|---|
codeception/codeception |
Testing framework (dev) |
codeception/module-asserts |
Codeception module for assertions (dev) |
codeception/module-phpbrowser |
Codeception module for browser testing (dev) |
codeception/module-rest |
Codeception module for REST API testing (dev) |
contributte/apitte |
API framework integration |
contributte/console |
Console commands integration |
elastic/elasticsearch |
Elasticsearch client |
firebase/php-jwt |
JWT (JSON Web Token) authentication |
nettrine/migrations |
Database migrations support |
nettrine/orm |
ORM integration for Nette |
php-amqplib/php-amqplib |
AMQP (RabbitMQ) client |
predis/predis |
Redis client |
- Clone the repository:
git clone https://github.com/jan-krcal/rest-api-example.git
- Install dependencies using Composer:
composer install
- Start the Docker containers:
docker-compose up --build
- Check and run migrations:
php bin/console.php migrations:status
php bin/console.php migrations:migrate -n
The project contains tests.
Run tests with:
php vendor/bin/codecept run
List of tests
Path | Testing framework | Description |
---|---|---|
tests/EmailTest.php |
Unit Test | ValueObject |
tests/AuthCest.php |
API Test | Tests authentication endpoints (login, registration, token validation) |
tests/OpenApiCest.php |
API Test | Tests OpenAPI endpoints |
php vendor/bin/phpcbf --standard=PSR12 <path>
php vendor/bin/phpstan analyse --memory-limit=512M
Method | Endpoint | Description | Request Body Fields |
---|---|---|---|
POST | /auth/register |
Register a new user | email , password , role , name |
POST | /auth/login |
Login and receive authorization token | email , password |
Method | Endpoint | Description | Request Body Fields |
---|---|---|---|
GET | /users |
List all users | — |
GET | /users/{id} |
Get data for a specific user | — |
POST | /users |
Create a new user | email , password , role , name |
PUT | /users/{id} |
Update user data | email (optional), name (optional), password (optional), role (optional) |
DELETE | /users/{id} |
Delete a user | — |
Method | Endpoint | Description | Request Body Fields |
---|---|---|---|
GET | /articles |
List all articles | — |
GET | /articles/{id} |
Get article details by ID | — |
POST | /articles |
Create an article | title , content |
PUT | /articles/{id} |
Update an article | title (optional), content (optional) |
This project is licensed under the MIT License. See the LICENSE file for details.