This is a simple Weather API developed using the OpenWeather.org API and the Go programming language. This API allows you to fetch weather information for a specific location by making HTTP requests.
To use this Weather API, you will need an API key from OpenWeather.org. You can obtain an API key by signing up on their website.
- Go programming language installed on your system.
- An OpenWeather.org API key.
-
Clone this repository to your local machine:
git clone https://github.com/yourusername/weather-api-golang.git
-
Change to the project directory:
cd weather-api-golang
-
Create a
.env
file in the project directory and add your OpenWeather.org API key:OPENWEATHER_API_KEY=your_api_key_here
-
Build and run the application:
go build ./weather-api-golang
The API server should now be running locally on port 8080.
To get weather information for a specific location, make a GET request to the following endpoint:
http://localhost:8080/weather?location={location}
Replace {location}
with the name of the city or location for which you want weather information.
Example Request:
GET http://localhost:8080/weather?location=New+York
Example Response:
{
"location": "New York",
"temperature": 72.5,
"humidity": 65,
"description": "Partly cloudy",
"icon": "http://example.com/weather-icon.png"
}
- If the API is unable to fetch weather data from OpenWeather.org, it will return a
500 Internal Server Error
response. - If the location is not found or the API key is invalid, it will return a
404 Not Found
response.
To deploy this Weather API to a production environment, you can follow these steps:
- Deploy the Go application to a web server or cloud platform of your choice.
- Set up environment variables for the OpenWeather.org API key in your production environment.
- Update the API endpoint in the documentation to point to your production server.
If you'd like to contribute to this project, please fork the repository and create a pull request with your changes.
This project is licensed under the MIT License - see the LICENSE file for details.
- Thanks to OpenWeather.org for providing the weather data.
- This project was created as a learning exercise in Go programming.
Please feel free to reach out with any questions or feedback!