Modus Create - Bak-end PHP API Exercise using Laravel
NHTSA API : https://one.nhtsa.gov/webapi/Default.aspx?SafetyRatings/API/5
- PHP : ^7.1.3
- Laravel : 5.6.*
git clone git@github.com:ansezz/backend-api-nhtsa.git
cd backend-api-nhtsa
# Install dependencies
composer install
./vendor/bin/phpunit
php artisan serv
Or use Laravel Homestead is better
Setup deploy System using Capistrano
- Server (Ubuntu /CentOs) with PHP, Nginx, Mysql (LEMP stack)
- Install Ruby
- Install Bundler
gem install bundler
- Install capistrano and some dependencies :
cd backend-api-nhtsa/deploy/deploy
# Install dependencies
bundle install
Now you should be able to execute :
cap -T
before this command, you need to change your server name and you IP server
- IP here :
deploy/deploy/config/deploy/dev.rb
- Server name here :
deploy/ops/nginx/sites-available/local.nhtsa.com
cap dev nginx:vhosts
cap dev nginx:restart
# Reload nginx service
cap dev nginx:reload
# Restart php fpm service
cap dev php:restart
cap dev deploy
Example API URL : http://local.nhtsa.com
GET http://local.nhtsa.com/vehicles/<MODEL YEAR>/<MANUFACTURER>/<MODEL>/
Example : http://local.nhtsa.com/vehicles/2015/Audi/A3
POST http://local.nhtsa.com/vehicles
Which, when called with an application/JSON body as follows:
{
"modelYear": 2015,
"manufacturer": "Audi",
"model": "A3"
}
GET http://local.nhtsa.com/vehicles/<MODEL YEAR>/<MANUFACTURER>/<MODEL>?withRating=true
Example : http://local.nhtsa.com/vehicles/2015/Audi/A3?withRating=true
generate api json documentation using Swagger
./vendor/bin/openapi ./app -o ./public/penapi.json --format json
You can see api DOC in PetStore.swagger.io,
Use Generated json : http://local.nhtsa.com/penapi.json.
- DigitalOcean cloud server.
- How To Install Linux, Nginx, MySQL, PHP (LEMP stack) in Ubuntu 16.04
- How To Use Capistrano to Automate Deployments: Getting Started
- Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma
- NHTSA API
Thank you for your time, if you have any question let me know.
Made by ❤️