Simple REST API for creating and rating car models.
Car make and model existence checked with third-party REST API.
Deployed at Heroku platform: link
Requires
git,
docker and
heroku clients installed +
heroku (free) account registered
Interpreter - Windows PowerShell || git v2.29.2 || docker v20.10.2 || heroku v7.47.11
# create folder for project
mkdir rate_cars
cd rate_cars
# get copy of the application's files
git clone https://github.com/gretkierewicz/rate_cars.git .
# there is empty .env file in repo to make building container straight-forward
# build app with docker-compose
docker-compose build
# login with heroku and create app for deployment
heroku login
heroku create
# login to container
heroku container:login
# create postgresql DB (this creates DATABASE_URL env variable as well)
heroku addons:create heroku-postgresql:hobby-dev
# push and release container
heroku container:push web
heroku container:release web
# create DB tables for cars app
heroku run python manage.py migrate cars
# start app in web-browser
heroku open
# Enjoy!
/cars/ -> post new car
/cars/popular/ -> list 5 most rated car models
/cars/{car_make}
/cars/{car_make}/models/
/cars/{car_make}/models/{model_name}
/cars/{car_make}/models/{model_name}/rate/{rate_value} -> post rate
json format example for posting cars:
{
"make": "Tesla",
"models": [
{"name": "Roadster"},
{"name": "Model 3"},
{"name": "Model X"},
{"name": "Model S"}
]
}
json format example for posting rate:
{
"rate": 5
}
-
Response's status codes
-
Valid data/url kwargs
- GET for all endpoints
- POST for /cars and /rate
- DELETE for car make and car model
-
Invalid data/url kwargs
- GET for endpoints with kwargs
- POST for /cars and /rate
- DELETE for car make and car model
-
- Deploying Django to Heroku With Docker by Michael Herman
- Django query-sets - annotate()
- docker-compose with django - docs
- heroku: Container Registry & Runtime (Docker Deploys)
- heroku: Django and Static Assets article (whitenoise)
- heroku: Local Development with Docker Compose
- StackOverFlow: nice solution with get_random_secret_key()
SECRET_KEY = os.environ.get('SECRET_KEY', default=get_random_secret_key())
- StackOverFlow: tip for local container update with a cleanup:
docker-compose up --force-recreate --build -d docker image prune -f
- StackOverFlow: providing DB migrations in local container:
#assume django in container named web docker-compose run web python3 manage.py migrate