PHPackages                             maurobonfietti/rest-api-slim-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. maurobonfietti/rest-api-slim-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

maurobonfietti/rest-api-slim-php
================================

Example of REST API with Slim PHP Framework.

v2.24.0(10mo ago)3061.7k95[3 issues](https://github.com/maurobonfietti/rest-api-slim-php/issues)MITPHPPHP ^8.0CI failing

Since Apr 22Pushed 10mo ago12 watchersCompare

[ Source](https://github.com/maurobonfietti/rest-api-slim-php)[ Packagist](https://packagist.org/packages/maurobonfietti/rest-api-slim-php)[ Docs](https://github.com/maurobonfietti/rest-api-slim-php)[ Fund](https://ko-fi.com/maurobonfietti)[ RSS](/packages/maurobonfietti-rest-api-slim-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (175)Used By (0)

REST API IN SLIM PHP
====================

[](#rest-api-in-slim-php)

This is an example of a RESTful API built using the [Slim PHP micro-framework](https://www.slimframework.com).

The API allows you to manage resources such as users, tasks, and notes.

You can also read this [README IN SPANISH](README_SPANISH.md).

[![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/600bc063da6c473ed8d7b919119e69b9169eb353c8faf18d5f1207ccc07d86c2/68747470733a2f2f7472617669732d63692e6f72672f6d6175726f626f6e6669657474692f726573742d6170692d736c696d2d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/maurobonfietti/rest-api-slim-php)[![Code Quality](https://camo.githubusercontent.com/40b3a7e2ead2181224c5fed2d924f55cddb2a8ab311a2542fca76cd8bb901d64/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6175726f626f6e6669657474692f6170692d726573742d736c696d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/maurobonfietti/api-rest-slimphp/?branch=master)[![Test Coverage](https://camo.githubusercontent.com/ca3f611be79bf470e2a469970298676cb40debe68e32c0b4cf80d48525d4549b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d6175726f626f6e6669657474692f6170692d726573742d736c696d7068702f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/maurobonfietti/api-rest-slimphp/coverage)[![Packagist Version](https://camo.githubusercontent.com/ece146eea6b846958db6ae7314ed6471c44ba51a6ccf566f59c8fbc2f64142fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6175726f626f6e6669657474692f726573742d6170692d736c696d2d706870)](https://packagist.org/packages/maurobonfietti/rest-api-slim-php)

[![alt text](https://camo.githubusercontent.com/251d62e6a3819a0a844eb97934081fae721cf61e553fefeac8c4a314e09873bc/68747470733a2f2f692e6962622e636f2f4b775a747043742f524553542d4150492d534c494d2d5048502e706e67 "Example of RESTful API with Slim PHP micro framework")](https://camo.githubusercontent.com/251d62e6a3819a0a844eb97934081fae721cf61e553fefeac8c4a314e09873bc/68747470733a2f2f692e6962622e636f2f4b775a747043742f524553542d4150492d534c494d2d5048502e706e67)

🖥️ TECHNOLOGIES USED:
---------------------

[](#️-technologies-used)

The leading technologies used in this project are:

- PHP 8
- Slim 3
- MySQL
- Redis
- dotenv
- PHPUnit
- JSON Web Tokens (JWT)

### Additional tools:

[](#additional-tools)

Also, I use other additional tools like:

- Docker &amp; Docker Compose
- Travis CI
- Swagger
- Code Climate
- Scrutinizer
- Sonar Cloud
- PHPStan
- PHP Insights
- Heroku
- CORS

⚙️ QUICK INSTALL:
-----------------

[](#️-quick-install)

### Requirements:

[](#requirements)

- Git
- Composer
- PHP &gt;= 8.0
- MySQL/MariaDB
- Redis (Optional)
- or Docker

### With Composer:

[](#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
```

[![How to install](https://camo.githubusercontent.com/72b50f0d7a3edafb1859a5d88339b2434324e6b4a019c30d3dd19b7f9ca97eb1/68747470733a2f2f63646e2e6c6f6f6d2e636f6d2f73657373696f6e732f7468756d626e61696c732f30636133363438626161363734646532626132663431383065373831656232312d776974682d706c61792e676966)](https://youtu.be/Zp_vod5wWWk)

### With Git:

[](#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:

[](#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:
-------------------

[](#️-troubleshooting)

If you get stuck, you can try [this guide](TROUBLESHOOTING.md) step by step.

🎦 TUTORIALS:
------------

[](#-tutorials)

Watch this mini-series of videos about Slim PHP (Spanish Audio 🔉 🇪🇸 🇦🇷).

### 📹 VIDEO #1

[](#video_camera-video-1)

[How to install and configure this API.](https://youtu.be/Zp_vod5wWWk)

### 🎥 VIDEO #2

[](#movie_camera-video-2)

[How to use JWT for Authentication.](https://youtu.be/TPnoPLBgZTg)

### 📹 VIDEO #3

[](#video_camera-video-3)

[Using Redis Cache.](https://youtu.be/qX_TVjxEZSc)

### 🎥 VIDEO #4

[](#movie_camera-video-4)

[Deploy Slim PHP on Heroku.](https://youtu.be/-F09LCgNuGg)

📦 DEPENDENCIES:
---------------

[](#-dependencies)

### LIST OF REQUIRE DEPENDENCIES:

[](#list-of-require-dependencies)

- [slim/slim](https://github.com/slimphp/Slim): Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
- [respect/validation](https://github.com/Respect/Validation): The most awesome validation engine ever created for PHP.
- [palanik/corsslim](https://github.com/palanik/CorsSlim): Cross-origin resource sharing (CORS) middleware for PHP Slim.
- [vlucas/phpdotenv](https://github.com/vlucas/phpdotenv): Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
- [predis/predis](https://github.com/nrk/predis/): Flexible and feature-complete Redis client for PHP and HHVM.
- [firebase/php-jwt](https://github.com/firebase/php-jwt): A simple library to encode and decode JSON Web Tokens (JWT) in PHP.

### LIST OF DEVELOPMENT DEPENDENCIES:

[](#list-of-development-dependencies)

- [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit): The PHP Unit Testing framework.
- [phpstan/phpstan](https://github.com/phpstan/phpstan): PHPStan - PHP Static Analysis Tool.
- [pestphp/pest](https://github.com/pestphp/pest): Pest is an elegant PHP Testing Framework with a focus on simplicity.
- [nunomaduro/phpinsights](https://github.com/nunomaduro/phpinsights): Instant PHP quality checks from your console.
- [vimeo/psalm](https://github.com/vimeo/psalm): A static analysis tool for finding errors in PHP applications.
- [rector/rector](https://github.com/rectorphp/rector): Instant Upgrades and Instant Refactoring of any PHP 5.3+ code.

🚥 TESTING:
----------

[](#-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:
---------------

[](#-screenshoots)

[![Screen Shot API using Browser](https://user-images.githubusercontent.com/24535949/121755366-58c07580-caed-11eb-9688-28183f80ab2a.png)](https://user-images.githubusercontent.com/24535949/121755366-58c07580-caed-11eb-9688-28183f80ab2a.png)

---

[![Screen Shot API using Postman](https://user-images.githubusercontent.com/24535949/121755370-5b22cf80-caed-11eb-8d82-bf1de5a9fa83.png)](https://user-images.githubusercontent.com/24535949/121755370-5b22cf80-caed-11eb-8d82-bf1de5a9fa83.png)

---

📚 DOCUMENTATION:
----------------

[](#-documentation)

### ENDPOINTS:

[](#endpoints)

#### INFO:

[](#info)

- Help: `GET /`
- Status: `GET /status`

#### USERS:

[](#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:

[](#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:

[](#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](extras/docs/endpoints.md).

### IMPORT WITH POSTMAN:

[](#import-with-postman)

All the API information is prepared for download and use as Postman collection: [Import Collection](https://www.getpostman.com/collections/b8493a923ab81ef53ebb).

[![Run in Postman](https://camo.githubusercontent.com/82ccefddb001e2caf9d399f1153fdda561cf3da341bb270e18644d516906bc64/68747470733a2f2f72756e2e7073746d6e2e696f2f627574746f6e2e737667)](https://app.getpostman.com/run-collection/b8493a923ab81ef53ebb)

🚀 DEPLOY:
---------

[](#-deploy)

You can deploy this API with Heroku.

[![Deploy](https://camo.githubusercontent.com/4eea217b02568cc464752586784ae247b22e99fea520a15b6f919b15934ba8ca/68747470733a2f2f7777772e6865726f6b7563646e2e636f6d2f6465706c6f792f627574746f6e2e737667)](https://heroku.com/deploy)

ℹ️ MORE INFORMATION:
--------------------

[](#ℹ️-more-information)

For more information about this project, check out my blog post: [How to create a REST API using Slim PHP](https://maurobonfietti.github.io/2019-06-03-rest-api-slim-php/).

You can also look at the [to-do list web app](https://github.com/maurobonfietti/rest-api-slim-php-web-app) I developed using this API in Angular.

💬 CONTRIBUTING:
---------------

[](#-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?
---------------------------

[](#heart-do-you-like-the-project)

You can support this project by inviting me a coffee ☕ 😋 or giving a **star** to this repo ⭐ 😎.

[ ![Buy Me a Coffee at ko-fi.com](https://camo.githubusercontent.com/87e7bc7e876c2c005c93d71c87e3ef6bb390bdfa6c06223c99603457d27c4a61/68747470733a2f2f617a3734333730322e766f2e6d7365636e642e6e65742f63646e2f6b6f6669332e706e673f763d32)](https://ko-fi.com/maurobonfietti)📄 LICENSE
---------

[](#page_facing_up-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance54

Moderate activity, may be stable

Popularity38

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Recently: every ~190 days

Total

174

Last Release

311d ago

Major Versions

0.60.0 → 1.0.0.x-dev2020-06-05

1.27.0 → 2.0.0.x-dev2020-09-28

PHP version history (4 changes)1.7.0.x-devPHP ^7.3

2.8.0.x-devPHP ^7.4

2.12.0.x-devPHP ^7.4 || ^8.0

2.15.0.x-devPHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24535949?v=4)[Mauro Bonfietti](/maintainers/maurobonfietti)[@maurobonfietti](https://github.com/maurobonfietti)

---

Top Contributors

[![maurobonfietti](https://avatars.githubusercontent.com/u/24535949?v=4)](https://github.com/maurobonfietti "maurobonfietti (1398 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![dinsen](https://avatars.githubusercontent.com/u/654037?v=4)](https://github.com/dinsen "dinsen (1 commits)")

---

Tags

apimysqlphprestrest-apislimslim-3slim-micro-frameworkslim-php-frameworkphpapirestslimmysqlREST APIslim3slim-micro-framework

###  Code Quality

TestsPest

Static AnalysisPHPStan, Psalm, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/maurobonfietti-rest-api-slim-php/health.svg)

```
[![Health](https://phpackages.com/badges/maurobonfietti-rest-api-slim-php/health.svg)](https://phpackages.com/packages/maurobonfietti-rest-api-slim-php)
```

###  Alternatives

[maurobonfietti/slim4-api-skeleton

Useful skeleton for RESTful API development, using PHP and Slim 4.

1392.3k](/packages/maurobonfietti-slim4-api-skeleton)[xeroapi/xero-php-oauth2

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

1054.3M14](/packages/xeroapi-xero-php-oauth2)[colorfield/mastodon-api

PHP wrapper for Mastodon API

282.9k1](/packages/colorfield-mastodon-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
