Implement a web service that would handle GET requests to path “weather” by returning the weather data determined by IP of the request originator. Upon receiving a request, the service should perform a geolocation search using a non-commercial, 3rd party IP to location provider. Having performed the reverse geo search service should use another non-commercial, 3rd party service to determine current weather conditions using the coordinates of the IP.
-
Clone the repository using the command
git clone https://github.com/Chaklader/WeatherAPI.git
-
Enter inside the repo:
cd WeatherAPI/
As the IP address to location finder database is shipped with the repo, we need to install Git LFS to fetch it. The installation instructions are provided below:Run the following command to install Git LFS using Homebrew (a popular package manager for macOS):
$ brew install git-lfs
- Download the Git LFS installer for Windows from the official Git LFS website: https://git-lfs.github.com/
- Run the downloaded installer (.exe file).
- Follow the installation wizard prompts to complete the installation process.
Run the following command to install Git LFS:
$ sudo apt update && sudo apt install git-lfs
-
Initialize Git LFS in the cloned repository: $ git lfs install
-
Fetch the Git LFS objects:
$ git lfs fetch
-
Run the following command to checkout the files with Git LFS:
$ git lfs checkout
The above procedure will make sure you have checkout the database src/main/resources/GeoLite2-City.mmdb
correctly
in the local repository.
Install PostgreSQL database locally and create a database named weatherdb
there. Our tables will be in the schema
named weather
but will be created by Flyway database versioning SQL provided in the src/main/resources/db/migration/table
location.
- Firstly, go inside the project repo and install all the dependencies using the command
$ mvn install -DskipTests
. Please, make sure you are using Java 17, for example I usejava version 17.0.6-zulu
- The project can be run from the terminal using the command
$ mvn spring-boot:run
- Otherwise, Run from a standard IDE such as IntelliJ. Make sure you are using Java 17 in the IDE
I have provided the Postman collection in the root of the project, first run the request GET Weather Data
that will
fetch the weather data for the IP address and store in the database. Then, we can run other queries for historical analysis.
See that I provided the IP address using X-Forwarded-For
header as the request can come from load balancer or proxy
and may not indicate the actual IP address for the client.
Run the suite WeatherApiTestSuite.java
and it will run all the tests for the project. You can also run the command
mvn clean install
that will run all the tests for the project