NI Task API
Steps
Set up
First, build docker container and run:
docker-compose build
docker-compose up -d
Install composer packages
docker-compose run --rm app composer install
copy .env.example to .env file and generate app key
cp .env.example .env
docker-compose run --rm app php artisan key:generate
Configuring Database
Run migration and seeders
docker-compose run --rm app php artisan migrate --seed
Configuring The Test Process and Running The Test
First, create sqlite database
touch database/database.sqlite
Run migration and seeders for testing
docker-compose run --rm app php artisan migrate --seed --env=testing
Run tests
docker-compose run --rm app php artisan test
How to use the API
API requests must include api. For example the root of the API is at /api.
Valid API request
curl -H "Accept: application/json" 'http://localhost/api/products'
You can use Postman collection for testing.
Auth
Route | HTTP Verb | Body | Header | Description |
---|---|---|---|---|
/auth | POST |
{'email':'foo@bar.com','password':'password'} | Get user token. |
User
Route | HTTP Verb | Body | Header | Description |
---|---|---|---|---|
/user | GET |
Empty | Authorization:Bearer token | Get current user data. |
/user/product | GET |
Empty | Authorization:Bearer token | Get user's orders. |
/user/product | POST |
{'sku' : 'traktor-pro-3'} | Authorization:Bearer token | Add new order to user. |
/user/product/:sku | DELETE |
Empty | Authorization:Bearer token | Delete user's order with sku. |
Product
Route | HTTP Verb | Body | Header | Description |
---|---|---|---|---|
/products | GET |
Empty | Authorization:Bearer token | Get all products. |
Personal Notes
If a user places an order for the same item multiple times and wants to cancel only one of these items, this is not possible using the current structure. My suggestion would be to create a unique key for each one of the orders and for each item in those orders, and carry out all communications through this key.