Spring MVC – Get Exchange Rate Values using REST API
People are doing business, and developing software for geographical locations. That means the calculation of a software price will vary globally. During those scenarios, we need to know about the exchange rates for a given currency. Nowadays many open source REST API calls are available and among that there is a call available to get exchange rates as well
https://api.exchangerate-api.com/v4/latest/<Any currency we need to give here>
Corresponding JSON Output:
Using Spring MVC, we can retrieve the JSON response that got from the REST API call and render it on our pages. Via a maven-driven project, let us do that. So, let us start with the full project structure and pom.xml file.
Step by Step Implementation
Invocation file : getExchangeRates.jsp
Let us try to give INR in the place of entering currency here
Now let us see the important java files for getting the exchange rate values
For rendering different exchange rate values, we need to modify the ExchangeRateController.java file according to our needs.
REST APIs are independent and highly scalable. Hence it can be consumed in web technologies like Java, JSP, Spring combinations, or other platforms too. Similarly, as it is providing the response as JSON, it is highly supportive to prepare android applications as well as IOS applications. In a way, we can say that world has shrunk and quick responses are available from many open-source REST API calls.
Please Login to comment...