Skip to content

ansezz/backend-api-nhtsa

Repository files navigation

Backend API NHTSA

Modus Create - Bak-end PHP API Exercise using Laravel

NHTSA API : https://one.nhtsa.gov/webapi/Default.aspx?SafetyRatings/API/5

Requirements

  • PHP : ^7.1.3
  • Laravel : 5.6.*

Installation

git clone git@github.com:ansezz/backend-api-nhtsa.git
cd backend-api-nhtsa
# Install dependencies
composer install

Run tests

./vendor/bin/phpunit

Run development server

php artisan serv

Or use Laravel Homestead is better

Development System

Setup deploy System using Capistrano

Requirements

  • 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

Update nginx vhosts

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  

Restart nginx service

cap dev nginx:restart  

Available command

# Reload nginx service
cap dev nginx:reload  

# Restart php fpm service
cap dev php:restart  

Run Deploy

cap dev deploy

Demo

Example API URL : http://local.nhtsa.com

Requirement 1

GET http://local.nhtsa.com/vehicles/<MODEL YEAR>/<MANUFACTURER>/<MODEL>/

Example : http://local.nhtsa.com/vehicles/2015/Audi/A3

Requirement 2

POST http://local.nhtsa.com/vehicles

Which, when called with an application/JSON body as follows:

{
 "modelYear": 2015,
 "manufacturer": "Audi",
 "model": "A3"
}

Requirement 3

GET http://local.nhtsa.com/vehicles/<MODEL YEAR>/<MANUFACTURER>/<MODEL>?withRating=true

Example : http://local.nhtsa.com/vehicles/2015/Audi/A3?withRating=true

API Doc

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.

References :

Thank you for your time, if you have any question let me know.

Made by ❤️