Skip to content

Latest commit

 

History

History
132 lines (113 loc) · 5.53 KB

README.md

File metadata and controls

132 lines (113 loc) · 5.53 KB

Restful WeatherAPIApp

Technologies used in project

  1. Python3
  2. Django4
  3. PostgreSQL - As production and dev DB
  4. ReactJS - Froent-end UI elements
  5. DRF (Django Rest Framework) - Using it to follow the REST methodology
  6. Nginx - As proxy server
  7. Docker - project deploying (dev and prod deploying versions)

Description

Index page


The WeatherApp index page represented by ReactJS elements. First what you seee - select box with countries. To see how WeatherApp is giving weather info just do steps:
  1. Choose country you want from first select


  2. After this you'll see select with cities - choose city you want
  3. When city choosed, the result with weather info will displayed down with grid displaying system

Countries and cities names in JSON format i took from this github repository - https://github.com/dr5hn/countries-states-cities-database.

Based on them i build files that contains only necessary info for app, files placed in weatherapp/static/weatherapp/files/json/:
  • countries_cities.json
  • countries.json

Tech features

  1. Restful
    • Client-server
    • Stateless
    • No request's data storage in DB or any other storage
    • Cacheability
    • Caching all server's responses for save time when client asks same info. Represented in project by Cache class.
    • Uniform interface
    • Giving neccessary info about content types and another actions that client can do with the asked resourse by using Django REST Framework.
  2. Business logic in Classes
  3. All business logic and necessary functionality represented in Classes. Using that architecture make able easily expanding existing functions by inheritance BaseAPI Abstract class and definition methods for new API calls. It also easier to auto-test it

That also make able to make your views look like short calling the object's methods https://github.com/AlexDolls/WeatherAPIApp/blob/master/weatherapp/views.py
@api_view(['GET'])
@parser_classes([JSONParser])   
def get_current_weather(request):
    city = request.GET.get("city", "Kiev")
    country_code = request.GET.get("countrycode", "")
    
    weather_api_object = CurrentWeather(GeoCording(city, country_code))
    
    weather_info = weather_api_object.send()
  
    return Response(weather_info)

Installation

Basic requirements

Install Docker Engine and Docker Compose on your PC.

Development

  1. Rename .env.dev-sample to .env.dev.

  2. Update the environment variables in the docker-compose.yml and .env.dev files.

  3. Build the images and run the containers:

    $ docker-compose up -d --build
  4. Don't forget to create superuser (needs to get access to admin panel)

    $ docker-compose exec web python3 manage.py createsuperuser

Test it out at http://localhost:8000(http://127.0.0.1:8000).

Production

Uses daphne + nginx.
  1. Rename .env.prod-sample to .env.prod and .env.prod.db-sample to .env.prod.db. Update the environment variables as you need.

  2. Build the images and run the containers:

    $ docker-compose -f docker-compose.prod.yml up -d --build
  3. Make migartions to DB

    $ docker-compose -f docker-compose.prod.yml exec web python3 manage.py makemigrations
    $ docker-compose -f docker-compose.prod.yml exec web python3 manage.py migrate
  4. Collect staticfiles

    $ docker-compose -f docker-compose.prod.yml exec web python3 manage.py collectstatic
  5. Don't forget to create superuser (needs to get access to admin panel)

    $ docker-compose exec web python3 manage.py createsuperuser

Test it out at http://localhost:1337(http://127.0.0.1:1337). To apply changes, the image must be re-built.