maurobonfietti/rest-api-slim-php
Composer 安装命令:
composer require maurobonfietti/rest-api-slim-php
包简介
Example of REST API with Slim PHP Framework.
README 文档
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
.envtogetenv(),$_ENVand$_SERVERautomagically. - 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.
maurobonfietti/rest-api-slim-php 适用场景与选型建议
maurobonfietti/rest-api-slim-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.7k 次下载、GitHub Stars 达 305, 最近一次更新时间为 2019 年 11 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「rest」 「api」 「mysql」 「slim」 「rest-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maurobonfietti/rest-api-slim-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maurobonfietti/rest-api-slim-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maurobonfietti/rest-api-slim-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Alfabank REST API integration
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
BlockCypher's PHP SDK for REST API
Helper classes for creating cookie headers
统计信息
- 总下载量: 1.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 305
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-04

