https://medium.com/@kitloong/create-crud-rest-api-with-laravel-api-resource-3146d91b38b6
This project uses Sail.
Please install Docker in order to start using Sail.
Install project dependencies:
composer install
Setup env:
cp .env.example .env
php artisan key:generate
Startup services:
./vendor/bin/sail up -d # Up on port 8080
PS: .env
has been pre-configured to support MySQL and Redis from sail.
Check service status:
curl http://localhost:8080/api/health
Migrate and seed database:
./vendor/bin/sail artisan migrate
./vendor/bin/sail artisan db:seed
Generate swagger page
./vendor/bin/sail artisan l5-swagger:generate
Open http://localhost:8080/api/documentation with your favourite browser to browse Swagger page.
Route: users.index
curl http://localhost:8080/api/users \
-H 'Accept: application/json'
Route: users.show
curl http://localhost:8080/api/users/1 \
-H 'Accept: application/json'
Route: users.store
curl -X POST http://localhost:8080/api/users \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d $'{
"name": "Name",
"email": "test@email.com",
"password": "password"
}'
Route: users.update
curl -X PUT http://localhost:8080/api/users/1 \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d $'{
"name": "Name",
"email": "test@email.com"
}'
Route: users.destroy
curl -X DELETE http://localhost:8080/api/users/7 \
-H 'Accept: application/json'