Example of REST API with Slim PHP micro framework.
This simple RESTful API, allows CRUD operations to manage resources like: Users, Tasks and Notes.
You can also read this README IN SPANISH.
Main technologies used:
PHP 7, Slim 3, MySQL, Redis, dotenv, PHPUnit and JSON Web Tokens.
Also, I use other aditional tools like:
Docker & Docker Compose, Travis CI, Swagger, Code Climate, Scrutinizer, Sonar Cloud, PHPStan, PHP Insights, Heroku and CORS.
More info about this project in my post: How to create a REST API using Slim PHP.
I implemented this API in this project. It's a todo list web app developed in Angular.
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
In your terminal execute this 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
You can use this project using docker and docker-compose.
Minimal Docker Version:
# 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
If you get stuck, you can try this guide step by step.
Mini-series of videos about Slim PHP (Spanish Audio 🔉 🇪🇸 🇦🇷).
Run all PHPUnit tests with
$ composer test > phpunit PHPUnit 9.2.3 by Sebastian Bergmann and contributors. ............................................................... 63 / 63 (100%) Time: 00:00.165, Memory: 18.00 MB OK (63 tests, 388 assertions)
Get All Tasks:
Get One Task:
Get All Notes:
Get One Note:
Also, you can see the API documentation with the full list of endpoints.
For more information on how to use the REST API, see the following documentation available on Postman Documenter.
All the information of the API, prepared to download and use as postman collection: Import Collection.
Also, you can view the OpenAPI Specification, using Swagger UI.
You can deploy this API with Heroku Free.
Check it out to this LIVE DEMO.
You can support this project inviting me a coffee ☕ 😋 or giving a star to this repo ⭐ 😎.
The MIT License (MIT). Please see License File for more information.