A PHP-based user-authenticated REST API boilerplate by [S. M. Sakil Imran], using:
git clone https://github.com/sakilimran/slim-eloquent-rest-boilerplate.gitclone git repocd slim-eloquent-rest-boilerplatechange working directory to root project foldercomposer installinstall dependencies- create
Config.phpfile from this:app/Config/Config-default.phpwith your configurations - create
phinx.ymlfile from this:phinx-default.ymlwith your configurations vendor/bin/phinx migraterun initial database migration
cd publicchange working directory to public folder and runphp -S localhost:8000via 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/
200API request successful400API request returned an error401Unauthorized (access token missing/invalid/expired)404API 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 |