This repository contains a simple Node.js application using Express, Axios, and WeatherAPI to provide weather information based on the client's IP address.
Installation Usage API Endpoints
git clone https://github.com/ObodoakorDavid/HNG-Task-One
cd HNG-Task-One
code .
npm install
WEATHER_API=your_weatherapi_key
npm start
The server will start on http://localhost:3000.
Returns a message directing the user to the /api/hello endpoint.
Response:
"Kindly head to /api/hello to view the task"
Fetches the weather information based on the client's IP address.
Query Parameters
visitor_name (optional): The name of the visitor. Response with query:
{
"client_ip": "Your IP address",
"location": "Your city",
"greeting": "Hello, Visitor Name!, the temperature is Temperature degrees Celsius in Your City"
}
Response without query:
{
"client_ip": "Your IP address",
"location": "Your city",
"greeting": "Hello, Anon!, the temperature is Temperature degrees Celsius in Your City"
}
Example Request
curl http://localhost:3000/api/hello?visitor_name=John
Example Response
{
"client_ip": "192.168.1.1",
"location": "New York",
"greeting": "Hello, John!, the temperature is 25 degrees Celsius in New York"
}
The application requires the following environment variable:
WEATHER_API: Your WeatherAPI key.
You can visit the WeatherApi website to sign up and get your api key.