tuupola / slim-api-skeleton
Slim 3 + Zend Table Gateway + Monolog API 框架
dev-master
2021-06-04 11:39 UTC
Requires
- php: ^7.3|^8.0
- crell/api-problem: ^3.3
- gofabian/negotiation-middleware: ^0.1.2
- laminas/laminas-db: ^2.12
- laminas/laminas-hydrator: ^3.2
- laminas/laminas-inputfilter: ^2.11
- league/fractal: ^0.13.0
- league/tactician: ^1.0
- lstrojny/functional-php: ^1.6
- micheh/psr7-cache: ^0.5.0
- monolog/monolog: ^1.17
- robmorgan/phinx: ^0.9.2
- slim/slim: ^3.9
- tuupola/base62: ^2.0
- tuupola/cors-middleware: ^1.0
- tuupola/slim-basic-auth: ^3.2
- tuupola/slim-jwt-auth: ^3.1
- vlucas/phpdotenv: ^2.0
Requires (Dev)
- overtrue/phplint: ^1.0
- phpunit/phpunit: ^7.3|^9.3
- squizlabs/php_codesniffer: ^3.5.4
- tuupola/http-factory: ^1.0
This package is auto-updated.
Last update: 2024-09-07 17:23:37 UTC
README
这是一个为 Composer 设计的 Slim 3 API 框架项目。项目使用 Zend Table Gateway 和 Phinx 进行数据库操作,Monolog 进行日志记录,以及 Fractal 作为序列化工具。包含了 Vagrant 虚拟机配置和 Paw 项目文件,便于开发。该框架尝试遵循 DDD 原则。
安装
使用 composer 安装最新版本。
$ composer create-project --no-interaction --stability=dev tuupola/slim-api-skeleton app
使用方法
如果您已安装 Vagrant,请启动虚拟机。
$ cd app
$ vagrant up
现在您可以通过 https://192.168.50.52/todos 访问 API。
获取令牌
$ curl "https://192.168.50.52/token" \
--request POST \
--include \
--insecure \
--header "Content-Type: application/json" \
--data '["todo.all"]' \
--user test:test
HTTP/1.1 201 Created
Content-Type: application/json
{
"token": "XXXXXXXXXX",
"expires": 1491030210
}
$ export TOKEN=XXXXXXXXXX
创建新的待办事项
$ curl "https://192.168.50.52/todos" \
--request POST \
--include \
--insecure \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/json" \
--data '{ "title": "Test the API", "order": 10 }'
HTTP/1.1 201 Created
ETag: "c39de417d4d1f5fe22d19cad68d672d8"
Last-Modified: Sat, 16 Apr 2016 10:21:50 GMT
Location: /todos/12Cf2ZjVvyu3A
Content-Type: application/json
{
"data": {
"uid": "12Cf2ZjVvyu3A",
"order": 10,
"title": "Test the API",
"completed": false,
"links": {
"self": "/todos/12Cf2ZjVvyu3A"
}
}
}
获取现有待办事项
$ curl "https://192.168.50.52/todos/12Cf2ZjVvyu3A" \
--include \
--insecure \
--header "Authorization: Bearer $TOKEN"
HTTP/1.1 200 OK
ETag: "c39de417d4d1f5fe22d19cad68d672d8"
Last-Modified: Sat, 16 Apr 2016 10:21:50 GMT
Content-Type: application/json
{
"data": {
"uid": "12Cf2ZjVvyu3A",
"order": 10,
"title": "Test the API",
"completed": false,
"links": {
"self": "/todos/12Cf2ZjVvyu3A"
}
}
}
更新现有待办事项的一部分
$ curl "https://192.168.50.52/todos/12Cf2ZjVvyu3A" \
--request PATCH \
--include \
--insecure \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/json" \
--header 'If-Match: "c39de417d4d1f5fe22d19cad68d672d8"' \
--data '{ "order": 27 }'
HTTP/1.1 200 OK
ETag: "ab6070930158fc8323aa4550aff438b7"
Last-Modified: Sat, 16 Apr 2016 10:27:16 GMT
Content-Type: application/json
{
"data": {
"uid": "12Cf2ZjVvyu3A",
"order": 27,
"title": "Test the API",
"completed": false,
"links": {
"self": "/todos/12Cf2ZjVvyu3A"
}
}
}
完全更新现有待办事项
$ curl "https://192.168.50.52/todos/12Cf2ZjVvyu3A" \
--request PUT \
--include \
--insecure \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/json" \
--header 'If-Match: "ab6070930158fc8323aa4550aff438b7"' \
--data '{ "title": "Full update", "order": 66, "completed": true }'
HTTP/1.1 200 OK
ETag: "451665ea7769851880f411750bbd873c"
Last-Modified: Sat, 16 Apr 2016 10:28:45 GMT
Content-Type: application/json
{
"data": {
"uid": "12Cf2ZjVvyu3A",
"order": 66,
"title": "Full update",
"completed": true,
"links": {
"self": "/todos/12Cf2ZjVvyu3A"
}
}
}
删除现有待办事项
$ curl "https://192.168.50.52/todos/12Cf2ZjVvyu3A" \
--request DELETE \
--include \
--insecure \
--header "Authorization: Bearer $TOKEN"
HTTP/1.1 204 No Content
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。