tuupola / slim-api-skeleton
Slim 3 + Zend Table Gateway + Monolog API skeleton
Installs: 3 168
Dependents: 0
Suggesters: 0
Security: 0
Stars: 312
Watchers: 24
Forks: 62
Open Issues: 6
Type:project
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-10-07 17:34:34 UTC
README
This is Slim 3 API skeleton project for Composer. Project uses Zend Table Gateway and Phinx for database operations, Monolog for logging, and Fractal as a serializer. Vagrant virtualmachine config and Paw project files are included for easy development. The skeleton tries to follow DDD principles.
Install
Install the latest version using composer.
$ composer create-project --no-interaction --stability=dev tuupola/slim-api-skeleton app
Usage
If you have Vagrant installed start the virtual machine.
$ cd app
$ vagrant up
Now you can access the api at https://192.168.50.52/todos
Get a token
$ 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
Create a new todo
$ 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"
}
}
}
Get an existing todo
$ 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"
}
}
}
Update part of an existing todo
$ 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"
}
}
}
Fully update an existing todo
$ 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"
}
}
}
Delete an existing todo
$ curl "https://192.168.50.52/todos/12Cf2ZjVvyu3A" \
--request DELETE \
--include \
--insecure \
--header "Authorization: Bearer $TOKEN"
HTTP/1.1 204 No Content
License
The MIT License (MIT). Please see License File for more information.