Code Monkey home page Code Monkey logo

weatherapp's Introduction

Weather Data Service API Documentation

This documentation provides an overview of the Weather Data Service API, including descriptions of each API endpoint, the choice of frameworks and technologies, and detailed steps for running and testing the project.

Project Description

The Weather Data Service is a RESTful API application designed to register and query weather sensor data. It allows for the registration of weather metrics such as temperature, humidity, and wind speed from various sensors and supports querying the average value of these metrics (temperature and humidity) over specific date ranges. The solution can be extended to support more metrics.

Technology Stack and Frameworks

  • Spring Boot: I have chosen Spring Boot framework for its ease of use, productivity, and the vast ecosystem. It simplifies the development of stand-alone, production-grade Spring-based applications.
  • Spring Data JPA: This library simplifies data access operations, reducing the amount of boilerplate code required and allowing more focus on the business logic.
  • H2 Database: This is an in-memory database used for simplicity and ease of setup, making it ideal for proof of concept, early development and testing phases.
  • Mockito: For writing unit and integration tests, I am using Mockito since due to its reliability and functionality for testing various aspects of the application.

How to Run the Application

  1. Prerequisites: Java JDK (version 8 or above) and Maven installed on your system.
  2. Clone the repository in your IDE of choice:
git clone https://github.com/n1dtec/WeatherApp.git
cd weatherapp
  1. Build the project
mvn clean install
  1. Run the application
mcn spring-boot:run

The application will start running on http://localhost:8080.

API Endpoints

Register Sensor Data

  • URL: /api/sensors/data
  • Method: POST
  • Description: Register sensor data for a specific sensor.
  • Request Body:
{
  "sensorId": "sensor123",
  "temperature": 22.5,
  "humidity": 45.0,
  "windSpeed": 5.5,
  "recordedAt": "2024-03-12T10:00:00"
}
  • Sample Response: HTTP 201 Created on success.

Query Average Sensor Data

  • URL: /api/sensors/average
  • Method: GET
  • Description: Query the average metric value for all sensors or a specific sensor in a date range.
  • Parameters:
    • sensorId (optional): The ID of the sensor. Omit to calculate the average for all sensors.
    • start: Start of the date range (ISO date-time format).
    • end: End of the date range (ISO date-time format).
  • Response:
{
  "averageTemperature": 23.5,
  "averageHumidity":50.0
}

Returns the average temperature and average humidity within the specified date range.

How to Test the Application

Using Postman or Curl

  1. Register Sensor Data:
  • Use the following command for Windows PowerShell:
curl -Method POST -uri http://localhost:8080/api/sensors/data -H @{ "content-type" = "application/json"} -Body '{"sensorId": "sensor123", "temperature": 22.5, "humidity": 45.0, "windSpeed": 5.5, "recordedAt": "2024-03-12T10:00:00"}'
  • Use the following command for other terminals:
curl -X POST http://localhost:8080/api/sensors/data -H 'Content-Type: application/json' -d '{"sensorId": "sensor123", "temperature": 22.5, "humidity": 45.0, "windSpeed": 5.5, "recordedAt": "2024-03-12T10:00:00"}'
  1. Query Average Sensor Data:
  • Use the following command for Windows PowerShell:
curl -Method GET -uri 'http://localhost:8080/api/sensors/average?start=2024-03-12T00:00:00&end=2024-03-13T00:00:00'
  • Use the following command for other terminals:
curl -X GET 'http://localhost:8080/api/sensors/average?start=2024-03-12T00:00:00&end=2024-03-13T00:00:00'

Using unit tests

  • Run the Tests using Maven:
mvn test

This command will execute all tests in the project, printing the results to the console.

weatherapp's People

Contributors

n1dtec avatar

Watchers

Ankur Gupta avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.