Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This 2022 tutorial example builds a Currency Conversion Service (CCS) that consumes an exchange value from a separate Forex Service (FS), multiplies it by a requested quantity, and returns the calculated amount. It demonstrates both a direct RestTemplate call and a declarative Feign client. The ports, exchange multiple, and response values below are illustrative tutorial data—not live foreign-exchange rates or production defaults.

Source tutorial: Spring Boot Tutorial, Part 3 (published July 1, 2022).

What the currency conversion service does

The CCS is a service consumer. It does not discover or calculate a current market exchange rate itself. Instead, it sends the source and destination currencies to the FS, receives a conversion multiple, and applies that multiple to the requested quantity:

totalCalculatedAmount = quantity × conversionMultiple

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For the tutorial’s example, a request for 10,000 EUR in INR is shown with a conversion multiple of 75, producing 750,000. Those numbers are sample fields from the tutorial response; 75 must not be treated as a current EUR-to-INR quote.

Example request and response

Request route

The controller exposes this GET route:

/currency-converter/from/{from}/to/{to}/quantity/{quantity}

A sample request is:

GET /currency-converter/from/EUR/to/INR/quantity/10000

Illustrative response fields

Field Meaning in the tutorial
from Source currency, such as EUR
to Destination currency, such as INR
conversionMultiple Value returned by the Forex Service
quantity Amount requested by the caller
totalCalculatedAmount Quantity multiplied by the conversion multiple
Forex Service port The tutorial’s illustrative upstream port, 8000

With the tutorial’s sample values, the arithmetic is 10,000 × 75 = 750,000. It is not a real-time pricing result.

Project pieces used in the example

The tutorial organizes the application around these pieces:

  • A Spring Boot application entry point
  • A Maven pom.xml, including Spring Boot Starter Web
  • A response bean representing the exchange-service result and calculated conversion
  • A REST controller exposing the currency-converter route
  • A Feign proxy interface for the alternative client path

The example names the application currency-conversion-service and uses port 8100 for CCS, while the illustrative FS runs on localhost port 8000. These are tutorial settings, not recommended production topology.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Calling Forex Service directly with RestTemplate

How the request flows

  1. The CCS receives from, to, and quantity as path variables.
  2. The controller prepares URI variables for the upstream route /currency-exchange/from/{from}/to/{to}.
  3. RestTemplate.getForEntity sends the GET request to the FS.
  4. The controller reads the returned conversion multiple.
  5. It multiplies that value by quantity and maps the result into the CCS response bean.

Representative controller logic

Map<String, String> uriVariables = new HashMap<>();
uriVariables.put("from", from);
uriVariables.put("to", to);

ResponseEntity<CurrencyExchange> response = restTemplate.getForEntity(
    "http://localhost:8000/currency-exchange/from/{from}/to/{to}",
    CurrencyExchange.class,
    uriVariables);

CurrencyExchange exchange = response.getBody();
responseBean.setFrom(from);
responseBean.setTo(to);
responseBean.setQuantity(quantity);
responseBean.setConversionMultiple(exchange.getConversionMultiple());
responseBean.setTotalCalculatedAmount(
    quantity.multiply(exchange.getConversionMultiple()));

The exact bean types and numeric representation depend on the project code. Preserve decimal precision appropriate for money rather than treating this tutorial arithmetic as a production accounting design.

Calling Forex Service through a Feign proxy

Define the proxy contract

Instead of constructing the HTTP call in the controller, the tutorial declares a CurrencyExchangeServiceProxy interface with a Feign client annotation and a mapped method for the exchange-value route. The interface describes the upstream operation; Feign supplies the HTTP implementation.

@FeignClient(name = "forex-service", url = "http://localhost:8000")
public interface CurrencyExchangeServiceProxy {
    @GetMapping("/currency-exchange/from/{from}/to/{to}")
    CurrencyExchange retrieveExchangeValue(
        @PathVariable("from") String from,
        @PathVariable("to") String to);
}

This is a representative shape of the tutorial’s contract. Check the current Spring Cloud OpenFeign documentation and your chosen dependency versions for annotation and configuration details before copying it.

Enable and inject Feign

  1. Enable Feign clients on the Spring Boot application.
  2. Inject CurrencyExchangeServiceProxy into the currency-conversion controller.
  3. Call the proxy method with the incoming currencies.
  4. Use the returned conversion multiple in the same quantity-multiplication step used by the direct client.
CurrencyExchange exchange = proxy.retrieveExchangeValue(from, to);
BigDecimal total = quantity.multiply(exchange.getConversionMultiple());

The business calculation does not change; only the way the CCS obtains the FS response changes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

RestTemplate versus Feign in this tutorial

Concern RestTemplate path Feign path
How the call is expressed Imperative controller code invokes getForEntity and supplies URI variables. An annotated interface method represents the upstream operation.
How the controller gets data It reads the ResponseEntity body returned by the client call. It invokes the injected proxy and receives the mapped response object.
Where the upstream address appears In the URL passed to the client call. In Feign client configuration or the client annotation.
Evidence for choosing one The tutorial demonstrates the direct approach. The tutorial says, “Feign provide a better alternative to RestTemplate to call REST API.” That is the tutorial author’s editorial assertion, not a benchmark or independently tested comparison.

Choose based on your project’s supported Spring stack, configuration needs, and team conventions. The source does not establish universal performance, reliability, or productivity differences.

Hardcoded address and the tutorial’s next step

The example points CCS at a fixed localhost Forex Service address. That is convenient for a two-service demonstration but does not distribute calls across multiple FS instances or handle changing service locations. The tutorial identifies client-side load distribution with Ribbon as a follow-on topic in the next installment. Treat that as historical series context: verify whether the load-balancing technology you choose is supported by your current Spring Cloud release.

Using this 2022 example with current Spring Boot

  • Use the tutorial to understand the consumer-provider flow, not as current framework-version guidance.
  • Verify Spring Boot, Spring Cloud, Feign, and Maven dependency compatibility in present-day official documentation.
  • Recheck endpoint paths, annotations, configuration keys, and client lifecycle APIs; the source contains inconsistent or typo-prone code and explanatory URLs.
  • Replace fixed localhost addresses with environment-specific configuration and a supported service-discovery or load-balancing approach for a real deployment.
  • Obtain exchange data from an authorized, current provider and define timeout, retry, error, precision, and audit policies before handling real money.

Further reading

For broader coverage of Spring Boot, Spring Cloud, resiliency, and deployment, see Spring Microservices in Action, Second Edition by John Carnell and Illary Huaylupo Sánchez (Manning, May 2021). It is optional background reading, not a requirement for following this example.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.