Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kitloong/laravel-api-practice
Create CRUD REST API with Laravel API Resource https://medium.com/@kitloong/create-crud-rest-api-with-laravel-api-resource-3146d91b38b6
https://github.com/kitloong/laravel-api-practice
api-resources laravel swagger
Last synced: about 2 months ago
JSON representation
Create CRUD REST API with Laravel API Resource https://medium.com/@kitloong/create-crud-rest-api-with-laravel-api-resource-3146d91b38b6
- Host: GitHub
- URL: https://github.com/kitloong/laravel-api-practice
- Owner: kitloong
- Created: 2020-06-06T16:04:34.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T20:56:05.000Z (over 1 year ago)
- Last Synced: 2023-04-19T22:10:33.014Z (over 1 year ago)
- Topics: api-resources, laravel, swagger
- Language: PHP
- Homepage:
- Size: 337 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Article
https://medium.com/@kitloong/create-crud-rest-api-with-laravel-api-resource-3146d91b38b6
## Setup
This project uses [Sail](https://laravel.com/docs/sail).
Please install [Docker](https://www.docker.com) in order to start using Sail.
Install project dependencies:
```shell
composer install
```Setup env:
```shell
cp .env.example .env
php artisan key:generate
```Startup services:
```shell
./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:
```shell
./vendor/bin/sail artisan migrate
./vendor/bin/sail artisan db:seed
```### Swagger
Generate swagger page
```shell
./vendor/bin/sail artisan l5-swagger:generate
```Open http://localhost:8080/api/documentation with your favourite browser to browse Swagger page.
## API example
### List
Route: `users.index`
```shell
curl http://localhost:8080/api/users \
-H 'Accept: application/json'
```### Get
Route: `users.show`
```shell
curl http://localhost:8080/api/users/1 \
-H 'Accept: application/json'
```### Create
Route: `users.store`
```shell
curl -X POST http://localhost:8080/api/users \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d $'{
"name": "Name",
"email": "[email protected]",
"password": "password"
}'
```### Update
Route: `users.update`
```shell
curl -X PUT http://localhost:8080/api/users/1 \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d $'{
"name": "Name",
"email": "[email protected]"
}'
```### Delete
Route: `users.destroy`
```shell
curl -X DELETE http://localhost:8080/api/users/7 \
-H 'Accept: application/json'
```