Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tony133/laravel-api-rest
Simple example of a API REST with Laravel 9.x
https://github.com/tony133/laravel-api-rest
api api-rest laravel laravel-application laravel9 php rest rest-api
Last synced: 6 days ago
JSON representation
Simple example of a API REST with Laravel 9.x
- Host: GitHub
- URL: https://github.com/tony133/laravel-api-rest
- Owner: Tony133
- License: mit
- Created: 2016-11-23T20:35:40.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2023-04-19T21:00:53.000Z (over 1 year ago)
- Last Synced: 2024-10-11T11:23:24.666Z (2 months ago)
- Topics: api, api-rest, laravel, laravel-application, laravel9, php, rest, rest-api
- Language: PHP
- Homepage:
- Size: 405 KB
- Stars: 220
- Watchers: 10
- Forks: 93
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Api Rest
[![Build Status](https://travis-ci.org/Tony133/laravel-api-rest.svg?branch=master)](https://travis-ci.org/Tony133/laravel-api-rest)
Simple example of a REST API with Laravel 9.x
## Install with Composer
```
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install or composer install
```## Set Environment
```
$ cp .env.example .env
```## Set the application key
```
$ php artisan key:generate
```## Run migrations and seeds
```
$ php artisan migrate --seed
```## Getting with Curl
```
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X GET http://127.0.0.1:8000/api/books
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X GET http://127.0.0.1:8000/api/books/:id
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X POST -d '{"title":"Foo bar","price":"19.99","author":"Foo author","editor":"Foo editor"}' http://127.0.0.1:8000/api/books
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X PUT -d '{"title":"Foo bar","price":"19.99","author":"Foo author","editor":"Foo editor"}' http://127.0.0.1:8000/api/books/:id
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X DELETE http://127.0.0.1:8000/api/books/:id
```## Pagination with Curl
```
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X GET http://127.0.0.1:8000/api/books?page=:number_page -H 'Authorization:Basic username:password or email:password'
```## User Authentication with Curl with middleware auth.basic.username
```
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X GET http://127.0.0.1:8000/api/books -H 'Authorization:Basic username:password'
```## User Authentication with Curl using middleware auth.basic
```
$ curl -H 'content-type: application/json' -H 'Accept: application/json' -v -X GET http://127.0.0.1:8000/api/books -H 'Authorization:Basic email:password'
```## Run App in container Docker with Laravel Sail
```
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/opt \
-w /opt \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
```## Run Start Application with Laravel Sail
```
./vendor/bin/sail up
```