Code Monkey home page Code Monkey logo

duplo_raincloud's Introduction

DuploRaincloud

Hello Duplolcloud employee! Thank you for taking the time to review my assessment project! I was asked to complete the following requirements within 48 hours:

The aim of this task is to build a simple API (backed by any kind of database). The application should be able to store weather forecast data in the database, based on provided latitude and longitude - you can use https://open-meteo.com/ to get a weather forecast. The API should be able to add (new longitude and latitude), delete or provide weather forecast. It should also provide an endpoint to list previously used longitudes and latitudes from the database, and choose them to provide the newest weather forecast.

I took some liberties concerning the shape of the returned forecast data as none was specified.

Improved Branch

I've created a branch named improved which contains numerous changes to the application that I completed after the 48 hour deadline.

Getting Started

I've included a Dockerfile and docker-compose file. After you build and run the image you can interact with the API.

Building and Running the Docker Container

Build the Docker image (npm ci may take a couple minute):

npm run containerize

# OR

docker build -t duplo_raincloud .

Run Docker Compose

npm run compose

# OR

docker compose up -d

The API should now be running! Try the following in your terminal:

curl -i localhost:4000/health

# OR

scripts/health_check.sh

If you see "OK" in the terminal after the health check, the service is running!

Custom Configuration

I've hardcoded configurations for the docker-compose file. If you wish to run and interact with the service locally, you can create a .env file at the workspace root. See the config file for details about the expected schema.

Interacting

I've included a Postman collection that you can import under postman/

I've also created scripts that preferentially use httpie. curl is used as a fallback if httpie is not installed. find them under scripts/

The scripts/ directory contains utility that can help you interact with the API:

  • add_location.sh: This script allows you to add a new location. You need to provide the latitude and longitude as arguments.
  • delete_location.sh: This script allows you to delete a location by its ID. You need to provide the ID as an argument.
  • fetch_forecast.sh: This script fetches the forecast for a specific location. You need to provide the latitude and longitude as arguments.
  • fetch_locations.sh: This script fetches all locations.
  • health_check.sh: This script checks the health of the API.
  • latest_forecast.sh: This script fetches the latest forecast for all locations.

API Endpoints

The API exposes the following endpoints:

  • GET /health: Checks the health of the API. Returns "OK" if the service is running.
  • GET /locations: Fetches all locations.
  • POST /locations: Adds a new location. Requires latitude and longitude in the request body.
  • DELETE /locations?id=:id: Deletes a location by its ID.
  • DELETE /locations?latitude=:latitude&longitude=:longitude Deletes a location by latitude and longitude.
  • GET /forecasts: Fetches the forecast for all locations.
  • GET /forecast/latest: Fetches the latest forecast for all locations.

You can interact with these endpoints using the provided scripts in the scripts/ directory or by using the included Postman collection in the postman/directory.

duplo_raincloud's People

Contributors

mick-io avatar

Watchers

 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.