Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Java Spring – GET Request with two parameters

I want to make a GET request to my server that receives two parameters, uniqueConfig and commitHash. The code for this operation in my Controller class is as follows:

@GetMapping("/statsUnique")
public ResponseEntity<Object> hasEntry(@RequestParam("uniqueConfig") String uniqueConfig,
                                       @RequestParam("commitHash") String commitHash) {
    Optional<Stats> statsOptional = 
        codecService.findByUniqueConfigAndCommitHash(uniqueConfig, commitHash);
    if (statsOptional.isPresent()) {
        return ResponseEntity.status(HttpStatus.OK).body(true);
    }
    return ResponseEntity.status(HttpStatus.OK).body(false);
}

The issue is, when I try to make the GET request using Postman, the server returns a 400 - Bad Request with the following error message:

MissingServletRequestParameterException: Required request parameter ‘uniqueConfig’ for method parameter type String is not present]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

my JSON on Postman looks like this:

{
    "commitHash": "ec44ee022959410f9596175b9424d9fe1ece9bc8",
    "uniqueConfig": "bowing_22qp_30fr_29.97fps_fast-preset"
}

Please note that those aren’t the only attributes and I’ve tried making the same request with all of them on the JSON. Nonetheless, I receive the same error.

What am I doing wrong here?

>Solution :

A GET request doesn’t (or at least shouldn’t) have a body. Parameters defined by the @RequestParam annotations should be sent in the query string, not a JSON body, i.e., the request should be something like

http://myhost/statsUnique?commitHash=commitHash&uniqueConfig=bowing_22qp_30fr_29.97fps_fast-preset
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading