Stars: 277
Forks: 93
Pull Requests: 135
Issues: 17
Watchers: 13
Last Updated: 2023-08-06 14:34:47
Example of REST API with Slim PHP micro Framework.
License: MIT License
Languages: PHP, Dockerfile, Makefile, HTML, Shell, Procfile
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.
The main technologies used in this project are:
Also, I use other aditional tools like:
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:
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
If you get stuck, you can try this guide step by step.
Watch this mini-series of videos about Slim PHP (Spanish Audio đ đĒđ¸ đĻđˇ).
How to install and configure this API.
How to use JWT for Authentication.
.env
to getenv()
, $_ENV
and $_SERVER
automagically.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)
Help: GET /
Status: GET /status
Login User: POST /login
Create User: POST /api/v1/users
Update User: PUT /api/v1/users/{id}
Delete User: DELETE /api/v1/users/{id}
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}
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 full list of endpoints.
All the information of the API, prepared to download and use as postman collection: Import Collection.
You can deploy this API with Heroku Free.
For more information about this project, check out my blog post: How to create a REST API using Slim PHP.
You can also take a look at the todo list web app I developed using this API in Angular.
If you would like to contribute to the project, please open an issue or submit a pull request. Contributions are always welcome!
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.