maurobonfietti / rest-api-slim-php
Example of REST API with Slim PHP Framework.
Fund package maintenance!
Ko Fi
Installs: 1 619
Dependents: 0
Suggesters: 0
Security: 0
Stars: 298
Watchers: 13
Forks: 97
Open Issues: 4
Requires
- php: ^8.0
- composer/composer: ^2.0
- firebase/php-jwt: ^5.0
- palanik/corsslim: dev-slim3
- predis/predis: ^1.1
- respect/validation: ^1.1
- slim/slim: ^3.12.3
- vlucas/phpdotenv: ^5.1
Requires (Dev)
- nunomaduro/phpinsights: ^2.0
- pestphp/pest: ^1.7
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^9.0
- rector/rector: ^0.12.4
- vimeo/psalm: ^4.18
- dev-master
- 2.23.0.x-dev
- v2.22.0.x-dev
- v2.21.0.x-dev
- v2.21.0
- v2.20.0.x-dev
- v2.20.0
- 2.19.0.x-dev
- 2.18.0.x-dev
- v2.18.0
- 2.17.0.x-dev
- v2.17.0
- 2.16.0.x-dev
- 2.16.0
- 2.15.0.x-dev
- 2.15.0
- 2.14.0.x-dev
- 2.14.0
- 2.13.0.x-dev
- 2.13.0
- 2.12.0.x-dev
- 2.12.0
- 2.11.0.x-dev
- 2.11.0
- 2.10.0.x-dev
- 2.10.0
- 2.9.0.x-dev
- 2.9.0
- 2.8.0.x-dev
- 2.8.0
- 2.7.0.x-dev
- 2.7.0
- 2.6.0.x-dev
- 2.6.0
- 2.5.0.x-dev
- 2.5.0
- 2.4.0.x-dev
- 2.4.0
- 2.3.0.x-dev
- 2.3.0
- 2.2.0.x-dev
- 2.2.0
- 2.1.0.x-dev
- 2.1.0
- 2.0.0.x-dev
- 2.0.0
- 1.27.0
- 1.26.0.x-dev
- 1.26.0
- 1.25.0.x-dev
- 1.25.0
- 1.24.0.x-dev
- 1.24.0
- 1.23.0.x-dev
- 1.23.0
- 1.22.0.x-dev
- 1.22.0
- 1.21.0.x-dev
- 1.21.0
- 1.20.0.x-dev
- 1.20.0
- 1.19.0.x-dev
- 1.19.0
- 1.18.0.x-dev
- 1.18.0
- 1.17.0.x-dev
- 1.17.0
- 1.16.0.x-dev
- 1.16.0
- 1.15.0.x-dev
- 1.15.0
- 1.14.0.x-dev
- 1.14.0
- 1.13.0.x-dev
- 1.13.0
- 1.12.0.x-dev
- 1.12.0
- 1.11.0.x-dev
- 1.11.0
- 1.10.0.x-dev
- 1.10.0
- 1.9.0.x-dev
- 1.9.0
- 1.8.0.x-dev
- 1.8.0
- 1.7.0.x-dev
- 1.7.0
- 1.6.0.x-dev
- 1.6.0
- 1.5.0.x-dev
- 1.5.0
- 1.4.0.x-dev
- 1.4.0
- 1.3.0.x-dev
- 1.3.0
- 1.2.0.x-dev
- 1.2.0
- 1.1.0.x-dev
- 1.1.0
- 1.0.0.x-dev
- 1.0.0
- 0.60.0.x-dev
- 0.60.0
- 0.59.0.x-dev
- 0.59.0
- 0.58.0.x-dev
- 0.58.0
- 0.57.0.x-dev
- 0.57.0
- 0.56.0.x-dev
- 0.56.0
- 0.55.0.x-dev
- 0.55.0
- 0.54.0.x-dev
- 0.54.0
- 0.53.0.x-dev
- 0.53.0
- 0.52.0.x-dev
- 0.52.0
- 0.51.0.x-dev
- 0.51.0
- 0.50.0.x-dev
- 0.50.0
- 0.49.0.x-dev
- 0.49.0
- 0.48.0.x-dev
- 0.48.0
- 0.47.0.x-dev
- 0.47.0
- 0.46.0.x-dev
- 0.46.0
- 0.45.0.x-dev
- 0.45.0
- 0.44.0.x-dev
- 0.44.0
- 0.43.0.x-dev
- 0.43.0
- 0.42.0.x-dev
- 0.42.0
- 0.41.0.x-dev
- 0.41.0
- 0.40.0.x-dev
- 0.40.0
- 0.39.0.x-dev
- 0.39.0
- 0.38.0.x-dev
- 0.38.0
- v0.37.0.x-dev
- 0.37.0
- 0.36.0.x-dev
- 0.36.0
- 0.35.0.x-dev
- 0.35.0
- v0.34.0.x-dev
- 0.34.0
- v0.33.0.x-dev
- 0.33.0
- v0.32.0.x-dev
- 0.32.0
- v0.31.0.x-dev
- 0.31.0
- 0.30.0
- 0.29.0
- 0.28.0
- 0.27.0
- 0.26.0
- 0.25.0
- 0.24.0
- 0.23.0
- 0.22.0
- 0.21.3
- 0.21.0
- 0.20.1
- dev-dependabot/composer/firebase/php-jwt-6.0.0
This package is auto-updated.
Last update: 2024-11-24 02:03:04 UTC
README
This is an example of a RESTful API built using the Slim PHP micro-framework.
The API allows you to manage resources such as users, tasks, and notes.
You can also read this README IN SPANISH.
đĨī¸ TECHNOLOGIES USED:
The leading technologies used in this project are:
- PHP 8
- Slim 3
- MySQL
- Redis
- dotenv
- PHPUnit
- JSON Web Tokens (JWT)
Additional tools:
Also, I use other additional tools like:
- Docker & Docker Compose
- Travis CI
- Swagger
- Code Climate
- Scrutinizer
- Sonar Cloud
- PHPStan
- PHP Insights
- Heroku
- CORS
âī¸ QUICK INSTALL:
Requirements:
- Git
- Composer
- PHP >= 8.0
- MySQL/MariaDB
- Redis (Optional)
- or Docker
With Composer:
You can create a new project running the following commands:
$ composer create-project maurobonfietti/rest-api-slim-php [my-api-name] $ cd [my-api-name] $ composer restart-db $ composer test $ composer start
With Git:
In your terminal, execute these commands:
$ git clone https://github.com/maurobonfietti/rest-api-slim-php.git && cd rest-api-slim-php $ cp .env.example .env $ composer install $ composer restart-db $ composer test $ composer start
With Docker:
You can use this project using docker and docker-compose.
Minimal Docker Version:
- Engine: 18.03+
- Compose: 1.21+
Commands:
# Start the API (this is my alias for: docker-compose up -d --build). $ make up # To create the database and import test data from scratch. $ make db # Checkout the API. $ curl http://localhost:8081 # Stop and remove containers (it's like: docker-compose down). $ make down
đ ī¸ TROUBLESHOOTING:
If you get stuck, you can try this guide step by step.
đĻ TUTORIALS:
Watch this mini-series of videos about Slim PHP (Spanish Audio đ đĒđ¸ đĻđˇ).
đš VIDEO #1
How to install and configure this API.
đĨ VIDEO #2
How to use JWT for Authentication.
đš VIDEO #3
đĨ VIDEO #4
đĻ DEPENDENCIES:
LIST OF REQUIRE DEPENDENCIES:
- slim/slim: Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
- respect/validation: The most awesome validation engine ever created for PHP.
- palanik/corsslim: Cross-origin resource sharing (CORS) middleware for PHP Slim.
- vlucas/phpdotenv: Loads environment variables from
.env
togetenv()
,$_ENV
and$_SERVER
automagically. - predis/predis: Flexible and feature-complete Redis client for PHP and HHVM.
- firebase/php-jwt: A simple library to encode and decode JSON Web Tokens (JWT) in PHP.
LIST OF DEVELOPMENT DEPENDENCIES:
- phpunit/phpunit: The PHP Unit Testing framework.
- phpstan/phpstan: PHPStan - PHP Static Analysis Tool.
- pestphp/pest: Pest is an elegant PHP Testing Framework with a focus on simplicity.
- nunomaduro/phpinsights: Instant PHP quality checks from your console.
- vimeo/psalm: A static analysis tool for finding errors in PHP applications.
- rector/rector: Instant Upgrades and Instant Refactoring of any PHP 5.3+ code.
đĨ TESTING:
Run all PHPUnit tests with composer test
.
$ composer test > phpunit PHPUnit 9.5.28 by Sebastian Bergmann and contributors. ........................................................ 56 / 56 (100%) Time: 00:00.697, Memory: 18.00 MB OK (56 tests, 343 assertions)
đ¸ SCREENSHOOTS:
đ DOCUMENTATION:
ENDPOINTS:
INFO:
-
Help:
GET /
-
Status:
GET /status
USERS:
-
Login User:
POST /login
-
Create User:
POST /api/v1/users
-
Update User:
PUT /api/v1/users/{id}
-
Delete User:
DELETE /api/v1/users/{id}
TASKS:
-
Get All Tasks:
GET /api/v1/tasks
-
Get One Task:
GET /api/v1/tasks/{id}
-
Create Task:
POST /api/v1/tasks
-
Update Task:
PUT /api/v1/tasks/{id}
-
Delete Task:
DELETE /api/v1/tasks/{id}
NOTES:
-
Get All Notes:
GET /api/v1/notes
-
Get One Note:
GET /api/v1/notes/{id}
-
Create Note:
POST /api/v1/notes
-
Update Note:
PUT /api/v1/notes/{id}
-
Delete Note:
DELETE /api/v1/notes/{id}
Also, you can see the API documentation with the complete list of endpoints.
IMPORT WITH POSTMAN:
All the API information is prepared for download and use as Postman collection: Import Collection.
đ DEPLOY:
You can deploy this API with Heroku.
âšī¸ MORE INFORMATION:
For more information about this project, check out my blog post: How to create a REST API using Slim PHP.
You can also look at the to-do list web app I developed using this API in Angular.
đŦ CONTRIBUTING:
If you would like to contribute to the project, please open an issue or submit a pull request. Contributions are always welcome!
â¤ī¸ DO YOU LIKE THE PROJECT?
You can support this project by inviting me a coffee â đ or giving a star to this repo â đ.
đ LICENSE
The MIT License (MIT). Please see License File for more information.