A warm welcome to tech-maze, in today's article we will see how we can get details from a website using api key without exposing api key in the url.
This is important not to expose your api key to others else it can be used by anyone and can be manipulated for some other purpose.
Please check the ReadMe file provided in GitHub repo to understand how to create an Api Key
I have implemented swagger as well for easy testing
Now lets dig in
This project has provided following two endpoints
First Endpoint :------------ fetch weather data (/weather)
Swagger : http://loaclhost:8080/swagger-ui.html
input should be pass as : city, country (for example - Mumbai,India)
Direct URL : https://localhost:8080/weather?q=city,country
Method Type : GET
Above request triggers following api call and return a response, which gives us weather data for the given city and country
url : https://api.openweathermap.org/data/2.5/weather
Request Type : GET
Sample Request :
query param: city, country
Api key and value: key-appid, value-api token
Sample Response :
please check the ReadMe file
Second Endpoint :------------ check the health of website (/healthcheck)
Method Type : GET
Above request triggers following api call and return status code 200 if success else return other code in case of failure
healthcheck service :- This call check the health of the website
url : https://openweathermap.org
Request Type : HEAD
Sample Request :
no parameter
Sample Response :
please check the ReadMe file
Project Requirements
JDK 1.11 or higher Gradle 7.3.2 or higher, Spring Boot 2.6.x
That's all folks, hope this will help at some extent, for more details please have a look in the below GitHub project, I will come up with another article shortly.
Git location for the demo : https://github.com/rohitmodi07/springboot-weatherApp
A Big thank you for checking out my article, this really encourage me to come up with more topics.
Here are some resources you might be interested ------------------------
Comments