/weather-api-demo

Golang application that mimics a simple REST API based weather application.

Primary LanguageGo

Weather API Demo

Purpose

The Weather API application provides weather information based on latitude and longitude. It is designed to demo a weather forecasts API and related data in a simple, RESTful manner.

Features

  • Retrieve weather data using geographical coordinates.
  • Provides temperature, weather conditions, and a description of how the temperature feels.
  • Supports CRUD operations for weather data management.

Design

Architecture

  • Language: Go
  • Framework: Gorilla Mux for routing
  • Middleware: Custom middleware for JSON responses, logging, and metrics

Endpoints

  • GET /api/v1/weather/{latitude},{longitude}: Retrieve weather information for a specific location.
  • PUT /api/v1/weather: Update weather data (not fully implemented here).
  • POST /api/v1/weather: Create new weather data (not fully implemented here).
  • DELETE /api/v1/weather: Delete weather data (not fully implemented here).

Environment Variables

Name Default Value Description
SERVER_ADDRESS :8080 Specifies the server address and port to bind the application to

Usage

Prerequisites

  • Go 1.22 installed on your machine.
  • Docker installed for containerization.

Running Locally

  1. Clone the repository:
git clone https://github.com/sooonmitch/weather-api-demo
cd weather-api-demo
  1. Run the application:
go run ./
  1. Access the API: Use curl or a tool like Postman to interact with the API
curl "http://localhost:8080/api/v1/weather/40,74"

Running with Docker

  1. Build the Docker image:
docker build -t app .
  1. Run the Docker container:
docker run -p 8080:8080 -e SERVER_ADDRESS=0.0.0.0:8080 app
  1. Test the API: Again, use curl or Postman:
curl "http://localhost:8080/api/v1/weather/40,74"

Releasing

Set the release tag:

git tag -a v1.0.0 -m "<Release Message>"

Push the release tag

git push origin v1.0.0

Run gorelease

goreleaser release

Testing

Run unit tests to ensure the application works as expected:

go test ./...

Notes

  • This is a demo, it will lack features and comforts
  • Modify the SERVER_ADDRESS environment variable as needed.
  • Ensure that ports used are not conflicting with other applications.