https://github.com/jan-krcal/rest-api-example
REST API Example (ORM, Apitte, Codeception, Redis, Elasticsearh, RabbitMQ, Nette)
https://github.com/jan-krcal/rest-api-example
apitte codeception elasticsearch jwt nette orm php rabbitmq redis
Last synced: 9 days ago
JSON representation
REST API Example (ORM, Apitte, Codeception, Redis, Elasticsearh, RabbitMQ, Nette)
- Host: GitHub
- URL: https://github.com/jan-krcal/rest-api-example
- Owner: jan-krcal
- License: mit
- Created: 2025-09-22T14:05:55.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-09-23T10:37:02.000Z (8 months ago)
- Last Synced: 2025-09-23T12:34:46.381Z (8 months ago)
- Topics: apitte, codeception, elasticsearch, jwt, nette, orm, php, rabbitmq, redis
- Language: PHP
- Homepage:
- Size: 74.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
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:**
```bash
git clone https://github.com/jan-krcal/rest-api-example.git
```
2. **Install dependencies using Composer:**
```bash
composer install
```
3. **Start the Docker containers:**
```bash
docker-compose up --build
```
4. **Check and run migrations:**
```bash
php bin/console.php migrations:status
php bin/console.php migrations:migrate -n
```
## โ
Tests
The project contains tests.
**Run tests with:**
```bash
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
```bash
php vendor/bin/phpcbf --standard=PSR12
```
```bash
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](LICENSE) file for details.