A simple API for storing weather reports
 
 
Go to file
Kenneth Barbour f4cd8c120c Initial commit 2024-03-29 16:10:31 -04:00
src Initial commit 2024-03-29 16:10:31 -04:00
.gitignore Initial commit 2024-03-29 16:10:31 -04:00
LICENSE.txt Initial commit 2024-03-29 16:10:31 -04:00
README.md Initial commit 2024-03-29 16:10:31 -04:00
openapi.json Initial commit 2024-03-29 16:10:31 -04:00
package-lock.json Initial commit 2024-03-29 16:10:31 -04:00
package.json Initial commit 2024-03-29 16:10:31 -04:00
send-sample-report Initial commit 2024-03-29 16:10:31 -04:00
server.mjs Initial commit 2024-03-29 16:10:31 -04:00

README.md

Weather Report API

This API allows users to submit and retrieve weather reports. Authenticated users can submit weather reports for their own stations. Any user may retrieve weather reports.

API Spec

The OpenAPI specification can be found in openapi.json.

Environment Variables

Variable Default Description
PORT 3000 Port to listen on for HTTP requests
NODE_ENV development Development environment; may be set to production
DB_FILE weather-reports.db Path to SQLite database file

Development

  1. npm install to install dependencies
  2. npm run dev to start the development server

Usage

Send a weather report

Send a JSON weather report by POST-ing to /v1/reports/{station_id}, where {station_id} is any unique identifier for your station.

For example, with CURL:

curl -X POST http://localhost:3000/v1/reports/TEST \
    -H "Content-Type: application/json" \
    -d '{"latitude": 40.7128, "longitude": -74.0060, "temperature": 72.5, "pressure": 1013.5, "humidity": 50.0}'

Get the most recent report

With CURL:

curl http://localhost:3000/v1/reports/TEST

Get report history

With CURL:

curl http://localhost:3000/v1/reports/TEST/history?start=2020-01-01T00:00:00&end=2020-01-02T00:00:00

Your result may include a next field. Add that to the query param to get the next set of results. For example:

curl http://localhost:3000/v1/reports/TEST/history?start=2020-01-01T00:00:00&end=2020-01-02T00:00:00&next=1234