This is a simple Flask application that provides an API endpoint to fetch the temperature of a city from OpenWeatherMap. The application can be Dockerized for easy deployment.
git clone https://github.com/yourusername/weather-api.git
- Visit OpenWeatherMap and sign up for an account.
- Obtain your API key from the dashboard.
docker build -t weather-api .
docker run -p 5000:5000 -e OPENWEATHER_API_KEY=<your_openweather_api_key> weather-api
Replace <your_openweather_api_key> with your actual OpenWeatherMap API key.
Access the API endpoint at http://localhost:5000/temperature.
- Endpoint: /temperature
- Method: GET
- Parameters:
- city (required): Name of the city.
- units (optional): Temperature units (imperial or metric). Defaults to metric.
curl http://localhost:5000/temperature?city=London&units=metric
{
"city": "London",
"temperature": 20.5,
"units": "metric"
}
To test your Weather API endpoint with the provided script, use the following command:
python test_script.py --endpoint http://your-api-endpoint/temperature # This will default to localhost if you don't specify, so only add if necessary
City Metric Imperial
New York 20.30 68.50
Los Angeles 24.00 75.20
Houston 26.70 80.10
London 14.90 58.90
Hong Kong 25.60 78.10