A PHP-based user-authenticated REST API boilerplate by [S. M. Sakil Imran], using:
git clone https://github.com/sakilimran/slim-eloquent-rest-boilerplate.git
clone git repocd slim-eloquent-rest-boilerplate
change working directory to root project foldercomposer install
install dependencies- create
Config.php
file from this:app/Config/Config-default.php
with your configurations - create
phinx.yml
file from this:phinx-default.yml
with your configurations vendor/bin/phinx migrate
run initial database migration
cd public
change working directory to public folder and runphp -S localhost:8000
via command line- or you can use Apache, set virtual host to public folder
Execute unit tests via PHPUnit by running ./vendor/bin/phpunit ./tests/
. You can debug tests via XDebug by running ./phpunit-debug ./tests/
(use Git Bash if on Windows).
This boilerplate's test suite features 100% code coverage out-of-the-box (see report in ./test/coverage/). To regenerate code coverage HTML report, run ./vendor/bin/phpunit --coverage-html ./tests/coverage/ --whitelist ./app/ ./tests/
200
API request successful400
API request returned an error401
Unauthorized (access token missing/invalid/expired)404
API endpoint not found
Endpoint | Parameters | Description |
---|---|---|
POST /users |
username string requiredpassword string required |
creates a user |
POST /users/login |
username string requiredpassword string required |
generates user access token |
All RESTful API endpoints below require a Authorization: Bearer xxxx
header set on the HTTP request, xxxx is replaced with token generated from the Authentication API above.
Endpoint | Parameters | Description |
---|---|---|
GET /categories |
n/a | lists all categories |
GET /categories/{id} |
n/a | gets category data by ID |
GET /categories/{id}/todo |
n/a | lists all todo items for a category |
POST /categories/ |
name string requiredcategory integer required |
creates a category |
PUT /categories/{id} |
name string optionalcategory integer optional |
updates a category |
DELETE /categories/{id} |
n/a | delete category and associated todo items |
Endpoint | Parameters | Description |
---|---|---|
GET /todo |
n/a | lists all todo items |
GET /todo/{id} |
n/a | gets todo item data by ID |
POST /todo |
name string requiredcategory integer required |
creates a todo item |
PUT /todo/{id} |
name string optionalcategory integer optional |
updates a todo item |
DELETE /todo/{id} |
n/a | deletes a todo item |