Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/jaswanth-gorripati/weather-api-server

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/jaswanth-gorripati/weather-api-server

  • v0.0.0-20240616182432-31237d80319f
  • Source
  • Go
  • Socket score

Version published
Created
Source

Weather API Server

This is a simple HTTP server written in Go that uses the OpenWeather API to fetch weather data based on latitude and longitude coordinates. The server exposes an endpoint that returns the weather condition and categorizes the temperature as cold, moderate, or hot.

Features

  • Fetches weather data from the OpenWeather API.
  • Returns weather condition (e.g., clear, rain, snow).
  • Converts temperature from Kelvin to Celsius and categorizes it as cold, moderate, or hot.
  • Validates requests to ensure they are GET requests.
  • Logs incoming request details.

Installation

  1. Clone the repository:

    git clone https://github.com/jaswanth-gorripati/weather-api-server.git
    cd weather-api-server
    
  2. Install dependencies:

    This project requires Go to be installed. You can download and install it from here.

  3. Build the server:

    go build -o weather-server
    

Usage

You can provide the OpenWeather API key either through a command-line argument or an environment variable.

Using Command-Line Argument

```sh
./weather-server -apikey YOUR_API_KEY
```

Using Environment Variable

```sh
export OPENWEATHER_API_KEY=YOUR_API_KEY
./weather-server
```

The server will start on port 8080 by default. You can change the port by setting the PORT environment variable.

Example Request

To fetch weather data, make a GET request to the /weather endpoint with lat and lon query parameters:

```sh
curl --location 'http://localhost:8080/weather?lat=78.37&lon=10.99'
```

Example Response

```json
{
    "temperature": "4.17°C",
    "temperature_condition": "Cold",
    "weather_condition": "Clouds"
}
```

FAQs

Package last updated on 16 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc