Challenge - 5 Problems
Service-to-service communication Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this RestTemplate call?
Consider a Spring Boot service using RestTemplate to call another service endpoint that returns a JSON object {"status":"ok"}. What will be the output of the following code snippet?
Spring Boot
RestTemplate restTemplate = new RestTemplate(); String response = restTemplate.getForObject("http://localhost:8081/api/status", String.class); System.out.println(response);
Attempts:
2 left
💡 Hint
The RestTemplate returns the raw response body as a String when using getForObject with String.class.
✗ Incorrect
The getForObject method returns the response body as a String exactly as received. Since the endpoint returns JSON, the output is the JSON string including quotes and escaped characters.
📝 Syntax
intermediate2:00remaining
Which option correctly declares a Feign client interface?
You want to create a Feign client in Spring Boot to call a remote service at 'http://inventory-service'. Which of the following interface declarations is correct?
Attempts:
2 left
💡 Hint
Feign clients must be interfaces and use correct annotations for HTTP methods and paths.
✗ Incorrect
Option C correctly declares a Feign client interface with name and url, uses @GetMapping with a leading slash, and defines the method signature properly.
🔧 Debug
advanced2:00remaining
Why does this WebClient call fail with a 404 error?
Given this WebClient call to a service endpoint '/api/data', the call returns 404 Not Found. What is the most likely cause?
Spring Boot
WebClient client = WebClient.create("http://localhost:8080"); String result = client.get() .uri("api/data") .retrieve() .bodyToMono(String.class) .block();
Attempts:
2 left
💡 Hint
Check how the URI is constructed when using WebClient with a base URL.
✗ Incorrect
Without a leading slash, the URI is appended directly to the base URL without a separator, causing an invalid URL and 404 error.
❓ state_output
advanced2:00remaining
What is the value of 'response' after this asynchronous WebClient call?
Consider this Spring Boot WebClient code snippet. What will be the value of the 'response' variable after execution?
Spring Boot
WebClient client = WebClient.create("http://localhost:8080"); final String[] response = {null}; client.get() .uri("/api/message") .retrieve() .bodyToMono(String.class) .subscribe(body -> { response[0] = body; }); System.out.println(response[0]);
Attempts:
2 left
💡 Hint
Remember that subscribe runs asynchronously and the print happens immediately.
✗ Incorrect
The subscribe method runs asynchronously, so the print statement executes before the response is assigned inside the lambda, leaving response null.
🧠 Conceptual
expert2:00remaining
Which statement best describes the difference between RestTemplate and WebClient in Spring Boot?
Choose the most accurate description of how RestTemplate and WebClient differ in service-to-service communication.
Attempts:
2 left
💡 Hint
Think about how each client handles request execution and threading.
✗ Incorrect
RestTemplate executes calls synchronously blocking the thread, whereas WebClient supports reactive programming with asynchronous non-blocking calls.