Simple API example using phramework/jsonapi 1.x
Available endpoints:
GET /article/
GET /article/{id}/
GET /article/{id}/relationships/tag/
GET /article/{id}/relationships/author/
POST /article/
{
"data": [
{
"type": "article",
"attributes": {
"title": "Sample title",
"body": "Sample body"
},
"relationships": {
"creator": {
"data": {
"id": "1",
"type": "user"
}
}
}
}
]
}
GET /tag/
GET /tag/{id}/
GET /tag/{id}/relationships/article/
GET /user/
GET /user/{id}/
Requirements:
To download dependencies
composer update
To initialize the SQLite database schema and records (required to run only once)
php ./tools/database.php
To start local web server at port 8004
execute using php build-in server
composer run
or
php -S localhost:8004 -t ./public/
You can access the article
collection using GET http://localhost:8004/article/
request.
You can also expose /public
to your web server, NOTE we are using an .htaccess
file to rewrite the urls.
To run all available tests (syntax check, unit and request tests)
composer test
- Unit tests available at
/tests/phpunit/
directory using PHPUnit - Request tests available at
/tests/testphase/
directory using phramework/testphase
Lint code using PSR-2 coding style
composer lint