Giter VIP home page Giter VIP logo

cars's Introduction

Cars

This is a web application using Django, and based on api data https://vpic.nhtsa.dot.gov/api/. App allows user to check existence of provided car brand and model, and adding it to the database if exists. Another function is possibility to rate cars.

Running the app in local development

The provided Docker Compose file allows you to run the app locally in development. To start the container, run:

$ docker-compose up

Once the stack has launched, you can test the application by executing GET/POST commands described below.

Executing the Tests

$ python ./manage.py test

REST API

The REST API to the example app is described below.

Get list of Cars

Request

/cars/
curl -i -H 'Accept: application/json' http://localhost:8000/cars/

Example responses

[
    {
        "id": 1,
        "car_make": "HONDA",
        "model_name": "CIVIC",
        "rate_point__avg": 3.6666666666666665
    },
    {
        "id": 2,
        "car_make": "AUDI",
        "model_name": "TT",
        "rate_point__avg": null
    },
    {
        "id": 3,
        "car_make": "FIAT",
        "model_name": "DUCATO",
        "rate_point__avg": 3.5
    }
]

Responses

Status Meaning Description
200 OK List of added cars

Create a new Car

Request

POST /cars/
curl -i -H 'Accept: application/json' -d 'car_make=sample-name&model_name=sample-model' http://localhost:8000/cars/

Body parameter

{
    "car_make": "Audi",
    "model_name": "TT"
}

Example responses

{
  "Message": "Car successfully added!"
}

Responses

Status Meaning Description
200 OK Car added do the database
422 Unprocessable Entity Wrong Payload Type

Rate a Car

Request

POST /rate/
curl -i -H 'Accept: application/json' -d 'car_make=sample-name&model_name=sample-model' http://localhost:8000/rate/

Body parameter

{
    "car_id": "101",
    "rate_point": "4"
}

Example responses

{
  "Message": "Car AUDI TT successfully rate to 4!"
}

Responses

Status Meaning Description
200 OK Rate added
404 Not Found Car not found

Get list of rated cars

Request

POST /popular/
curl -i -H 'Accept: application/json' http://localhost:8000/popular/

Example responses

[
  {
    "id": 1,
    "car_make": "HONDA",
    "model_name": "CIVIC",
    "total_rate_entries": 3
  },
  {
    "id": 3,
    "car_make": "FIAT",
    "model_name": "DUCATO",
    "total_rate_entries": 2
  },
  {
    "id": 2,
    "car_make": "HONDA",
    "model_name": "CIVIC",
    "total_rate_entries": 0
  },
  {
    "id": 4,
    "car_make": "AUDI",
    "model_name": "TT",
    "total_rate_entries": 0
  }
]

Responses

Status Meaning Description
200 OK List of cars sorted by popularity

Demo version

http://cars-rate.herokuapp.com/

cars's People

Contributors

juju-and avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.