Here is the GET mapping in my backend:
@GetMapping(value = "search")
public List<Cat> search(@RequestBody CatDto catDto) {
return catService.search(catDto);
}
I am trying to send a GET request to retrieve a list using Angular's HttpClient
. Since GET requests cannot have a request body, I attempted the following in my component.ts
:
search(cat: Cat): Observable<Cat[]> {
let params = new HttpParams();
params = params.append('name', cat.name);
params = params.append('rating', (cat.rating).toString());
params = params.append('birthday', (cat.birthday).toLocaleDateString());
return this.httpClient.get<Cat[]>(this.messageBaseUri+'/search', {responseType: 'json', params});
}
However, I encountered the error:
Required request body is missing
Coming from my backend. Is there a way to achieve this without modifying my backend or do I need to change my backend endpoint as follows:
@GetMapping(value = "search")
public List<Cat> search(@RequestParam String name,
@RequestParam Integer rating,
@RequestParam Date birthday) {
return catService.search(name, rating, birthday);
}