A REST example for Yii I created for a job application.
- PHP 7
- Composer
- Export or checkout the files
- run
composer update - run
php yii serve --port=8888to start the php build in web server (if you use another port you also have to change the test suites config files)
To manually test the api, fire up Postman or the like. The response is always JSON, regardless of the Accept-Encoding header.
GET api/v1/categories
GET api/v1/categories/:id
You can expand the category to show it's children or parent (if any):
GET api/v1/categories/:id?expand=children
GET api/v1/categories/:id?expand=parent
GET api/v1/categories/:id?expand=children,parent
GET api/v1/categories/:slug
Here you can also expand the query.
POST api/v1/categories
Body should be a valid application/json:
{
"name":"new category",
"slug":"new-cat",
"parentCategory":null,
"isVisible": 1
}Required are name and slug, where the slug must be unique in all categories.
PATCH api/v1/categories/:id
PUT api/v1/categories/:id
Body should be a valid application/json:
{
"isVisible": 0
}DELETE api/v1/categories/:id
Run tests:
vendor\bin\codecept run
or with coverage report:
vendor\bin\codecept run --coverage --coverage-html
You can then find the coverage report in
tests/_output/coverage/
Licensed under the MIT license.