This is a mini API as an example with Category
and Merchants
entities and all their endpoints (GET/POST/PUT/DELETE). This API doesn't have any authentication because the object is only showing a working API.
- git
- Docker
Clone the repository
git clone https://github.com/alejandroescanes/giving-assistant.git
cd giving-assistant
This command will create a local image which will be used to create the container. This step could take some time because will run composer install
to create a functional image.
docker build -t ga .
This command will create a temporary container and will run all the unit tests.
docker run --rm -t ga ./vendor/bin/phpunit --testdox
This commant will create the container where the api will run.
docker run -p 8008:80 --name ga_container -t ga
Get all categories
GET - http://0.0.0.0:8008/categories
e.g. http://0.0.0.0:8008/categories
Get category by id
GET - http://0.0.0.0:8008/categories/{id}
e.g. http://0.0.0.0:8008/categories/1
Get all merchants by category id
GET - http://0.0.0.0:8008/categories/{id}/merchants
e.g. http://0.0.0.0:8008/categories/1/merchants
Get all merchants
GET - http://0.0.0.0:8008/merchants
e.g. http://0.0.0.0:8008/merchants
Get marchant by id
GET - http://0.0.0.0:8008/merchants/{id}
e.g. http://0.0.0.0:8008/merchants/1
Also the code has POST/PUT/DELETE endpoints for Categories and Merchants that you can try. The body for POST AND PUT endpoints are:
Category
{
"name": "This is the name"
}
Merchant
{
"name": "This is the name",
"category_id": 1
}
If you have any issues with the docker image you can run this alternative commands to get the api working.
git php 7.2 or higher composer
composer install
./vendor/bin/phpunit --testdox
php artisan migrate:fresh --seed
php -S 0.0.0.0:8008 -t public