0

How do i Pass a Map of Key Value pairs to a GET REST API,

Here is the call to the resource .. I am getting a method not allowed

String queryMap= String.format("{'softwareversion':'%s','peril':'%s','analysistype':'%s', 'region':'%s'}", "HD18", "Flood", "EP", "USFL");
        String url = String.format("http://localhost:%d/templates/modelprofile?queryMap=%s", API_APPLICATION_RULE.getLocalPort(),queryMap);

    Response response = ClientBuilder.newClient()
            .target(url)
            .request()
            .header("Authorization", getToken())
            .get();

I have the resource as below

@GET
    @Path("/{templateType}")
    @Timed
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "Get templates based on peril/region,version and type",
            httpMethod = ApiConstants.GET)
    @ApiResponses(value = {
            @ApiResponse(code = ApiConstants.INT_200,
                    message = "TemplateReader was retrieved successfully from the database."),
            @ApiResponse(code = ApiConstants.INT_400,
                    message = "Bad request (wrong or missing inputs)"),
            @ApiResponse(code = ApiConstants.INT_500,
                    message = ApiConstants.INTERNAL_SERVER_ERROR)
    })
public Template getTemplate(@ApiParam(hidden = true) @Auth User user,
                                  @ApiParam(name = "templateType", value = "templateType")
                                  @PathParam("templateType") String templateType,
                                  @ApiParam(name = "queryMap", value = "queryMap")
                                    @RequestParameters Map<String,String> queryMap
                                  ) throws ApiException
user3897533
  • 417
  • 1
  • 8
  • 24
  • You don't. You send the data in a data format like JSON. It will get deserialized on the server into a Map or a POJO. BTW, what framework are you using? – Paul Samsotha Jul 10 '18 at 12:49

1 Answers1

0

You can pass it using request parameter as below.

@RequestMapping(name = "/url/", method = RequestMethod.GET)
public void method_name(@RequestParam(name = "map_name")Map<String, Object> requestMap){
  //Process map and perform your logic
}
Tharsan Sivakumar
  • 6,351
  • 3
  • 19
  • 28