I am currently working on a Spring Boot application wrapping an external REST API into my own GraphQL API.
So far, I've did this method returning a SerieDetails :
public SerieDetails findOrThrow(long id) throws RuntimeException {
try {
return this.webClient
.get()
.uri("/tv/{id}?api_key={apiKey}&language={lang}", id, this.apiKey, this.lang)
.retrieve()
.bodyToMono(SerieDetails.class)
.log()
.block();
} catch(Exception e ) {
throw new RuntimeException("Can't reach the API");
}
}
Turning this JSON into my own object :
{
"id": 71912,
"name": "The Witcher",
"overview": "Geralt of Rivia, a mutated monster-hunter for hire, journeys toward his destiny in a turbulent world where people often prove more wicked than beasts."
"last_air_date": "2019-12-20",
...
}
Which works great. But now I am doing another call returning a list of SerieDetails with a given query and it returns the result under the result array :
{
"page": 1,
"results": [
{
"id": 71912,
"name": "The Witcher",
"overview": "Geralt of Rivia, a mutated monster-hunter for hire, journeys toward his destiny in a turbulent world where people often prove more wicked than beasts."
"first_air_date": "2019-12-20",
...
},
{
"id": 106541,
"name": "The Witcher: Blood Origin",
"overview": "Set in an elven world 1200 years before the world of The Witcher, the show charts the origins of the very first Witcher, and the events that lead to the pivotal “conjunction of the spheres,” when the worlds of monsters, men, and elves merged to become one.",
"first_air_date": "2002-09-22",
...
}
]
}
And I don't know how to get to it with WebClient. I tried this so far :
public List<SerieDetails> findByQuery(String query) {
return this.webClient
.get()
.uri("/search/tv?api_key={apiKey}&language={lang}&query={query}", this.apiKey, this.lang, query)
.retrieve()
.bodyToFlux(SerieDetails.class)
.log()
.collect(Collectors.toList())
.block();
}
But it doesn't work.