A REST service exposes application functionality through HTTP endpoints. In a Spring application, a REST API can accept a question, delegate it to an AI service, and return the generated answer as JSON. section 1.1 section 1.1.2
A minimal Spring REST endpoint connects these pieces:
- A POST request targets /ask and carries a Question object in its request body. section 1.1.2
- A controller delegates the request to BoardGameService rather than performing the AI interaction itself. section 1.1.2
- The service submits the question through ChatClient and wraps the generated text in an Answer record. section 1.1.2
Question-answer endpoint
A client sends a question to POST /ask. AskController accepts the JSON request, calls BoardGameService.askQuestion(), and returns an Answer as application/json. The service uses ChatClient's fluent prompt(), user(), call(), and content() operations to obtain the response. section 1.1.2
Listing 1.3 A controller that handles requests working with BoardGameService
package com.example.boardgamebuddy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class AskController {
private final BoardGameService boardGameService;
public AskController(BoardGameService boardGameService) { #1
this.boardGameService = boardGameService;
}
@PostMapping(path="/ask", produces="application/json")
public Answer ask(@RequestBody Question question) {
return boardGameService.askQuestion(question); #2
}
}
Inspect the controller listing to see request-body binding, endpoint mapping, dependency injection, and service delegation together. section 1.1.2





















