Skip to content

jan-krcal/rest-api-example

Repository files navigation

REST API Example (ORM, Apitte, Codeception, Redis, Elasticsearh, RabbitMQ, Nette)

Sample REST API for working with two entities — articles and users, with authorization support.

🐳 Docker Setup

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.

Important

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.

⚙️ Installed Extensions and Framework

This project runs on the Nette Framework and uses the following key Composer packages:

Installed 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

🚀 Startup Instructions

  1. Clone the repository:
git clone https://github.com/jan-krcal/rest-api-example.git
  1. Install dependencies using Composer:
composer install
  1. Start the Docker containers:
docker-compose up --build
  1. Check and run migrations:
php bin/console.php migrations:status
php bin/console.php migrations:migrate -n

✅ Tests

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

🧹 Code Quality and Static Analysis

php vendor/bin/phpcbf  --standard=PSR12 <path>
php vendor/bin/phpstan analyse --memory-limit=512M

📚 API Endpoints with Request Body Fields

Authentication

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

User Management (admin only)

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

Article Management

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)

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

About

REST API Example (ORM, Apitte, Codeception, Redis, Elasticsearh, RabbitMQ, Nette)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published