eheikes / weather-api

The weather-api project exposes a Rest Api which proxies requests to the openweathermap apis to retrieve the weather for a given lat/lon.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overview

The weather-api project exposes a Rest Api which proxies requests to the openweathermap apis to retrieve the weather for a given lat/lon. Configuration of the weather-api project is done through dotenv (.env and .env.local files). Users of weather-api can utilize the npm run scripts defined in package.json to start, test, lint, etc.

Prerequisites

  1. NodeJS 18.2.0

  2. NPM 8.11.0

  3. OpenWeatherMap OneCall Subscription and API Key

    1. This subscription and api key can be obtained from https://openweathermap.org/guide

    2. Once obtained the api key must be configured in .env.local

Configuration

Configuration of the weather-api project utilizes dotenv. All configuration parameters can be seen in the .env file. To prevent accidentally adding api keys into source code it is recommended that the user copies the .env to create a .env.local in the root directory.

Running the project

To run the weather-api project:

  1. From the root of the project run: npm run start

Executing the api

You can use your favorite Rest Api tool like curl, postman, or a browser to execute the weather-api rest apis. Here is an example using curl: curl 'http://localhost:8080/weather/current?lat=90&lon=90'

Note: the above link assumes weather-api is running on port 8080. This can be changed using the PORT environment variable through .env.local .

Logging

Logs are written to ./output/weather-api.log

Testing / Coverage

Unit tests can be executed by executing the npm test run script. From the root of the project run: npm run test

Test coverage can be calculated by executing the following from the root of the project: npm run coverage. Unit test coverage minimums are defined in package.json.

OpenAPI Doc

The weather-api project exposes an OpenAPI document hosted at http://localhost:8080/api-docs/openapi.json .

An interactive Swagger UI is available at http://localhost:8080/api-docs

Note: the above link assumes weather-api is running on port 8080. This can be changed using the PORT environment variable through .env.local .

About

The weather-api project exposes a Rest Api which proxies requests to the openweathermap apis to retrieve the weather for a given lat/lon.

License:MIT License


Languages

Language:JavaScript 98.9%Language:Shell 1.1%