Reputation: 1521
I am trying to create a @GetMapping
with the following url:
{url}?id=9879948989980798
instead of traditional:
{url}/9879948989980798
At present, my controller method looks like this:
@GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(
value = "Get all guilds associated to a tag by tag Id",
response = Guild.class,
responseContainer = "List",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Response> getAll(
@RequestParam(required=true) String tagId) {
Response response = new Response();
List<Guild> dbGuilds = Service.getAll(UUID.fromString(tagId));
response.setResponse(dbGuilds);
return new ResponseEntity<>(response, HttpStatus.OK);
}
This leads to the following error:
TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.
What should be done to get the expected URL (mentioned at the top of the question)?
The following is the executed curl request(ignore the non matching id here, the above ones are randomly typed out):
curl -X GET "http://localhost:8080/users/tags" -H "accept: application/json" -H "EYDX-GEMS-SERVICE-API-KEY: rgeeh" -H "authorization: erherherh" -H "Content-Type: application/json" -d "\"9a367f0b-077d-4a35-acd2-b2c0b84dd716\""
Upvotes: 0
Views: 2405
Reputation: 46
You need @RequestParam(value = "id") if you need explicit use id=?
Try this:
@RequestMapping("/")
@ResponseBody ResponseEntity<String> getAll(@RequestParam(value = "id", required = true) String id) {
return new ResponseEntity<String>("You ID is ".concat(id).concat(", welcome!"), HttpStatus.OK);
}
And GET http://localhost:8080/?id=999 :)
Upvotes: 2
Reputation: 382
You shall show us the cURL of your REST call. That error is generally due to the presence of a -d option followed by a body request in your cURL. Maybe you're POSTing instead of GETting ?. Are you calling by Postman? Make sure you're calling by GET method or sending no body request json.
Upvotes: 0