Logo Lanfrica

steve-ongera/Kenya-County-Weather-API

Domain:

climate

Record type:

software
Creator:
ste
Host:
A full-stack weather application consisting of a Django REST API backend and a Java console client. This project demonstrates end-to-end API development and consumption. # Kenya County Weather API A full-stack weather application consisting of a Django REST API backend and a Java console client. This project demonstrates end-to-end API development and consumption. ## 🌟 Features - **Django REST API** - Custom weather service for Kenyan counties - **Java Console Client** - Simple weather app that consumes the API - **5 Pre-seeded Counties** - Nairobi, Mombasa, Kisumu, Eldoret, and Nakuru - **JSON Response Format** - Easy to parse and extend ## 📋 Prerequisites ### Backend (Django) - Python 3.8+ - Django 4.x - Django REST Framework ### Frontend (Java) - Java JDK 8+ - org.json library (json-20240303.jar) ## 🚀 Installation & Setup ### Part 1: Django Backend Setup #### 1. Create the Django project ```bash django-admin startproject weather_api cd weather_api python manage.py startapp weather ``` #### 2. Install Django REST Framework ```bash pip install djangorestframework ``` #### 3. Configure settings Add to `weather_api/settings.py`: ```python INSTALLED_APPS = [ ... 'rest_framework', 'weather', ] ``` #### 4. Create the Weather Model In `weather/models.py`: ```python from django.db import models class CountyWeather(models.Model): county = models.CharField(max_length=100, unique=True) temperature = models.FloatField() humidity = models.IntegerField() condition = models.CharField(max_length=100) def __str__(self): return f"{self.county} - {self.condition}" ``` #### 5. Create Seed Command Create `weather/management/commands/seed_weather.py`: ```python from django.core.management.base import BaseCommand from weather.models import CountyWeather class Command(BaseCommand): def handle(self, *args, **kwargs): data = [ {"county": "Nairobi", "temperature": 25.4, "humidity": 60, "condition": "Sunny"}, {"county": "Mombasa", "temperature": 30.2, "humidity": 70, "condition": "Humid"}, {"county": "Kisumu", "temperature": 27.1, "humidity": 65, "condition": "Cloudy"}, {"county": "Eldoret", "temperature": 22.5, "humidity": 55, "condition": " …