-1

An example URL is this:

api/v1/query?query=up{device="Device_1"}

where Device_1 is a @PathVariable

I test it with:

@RequestMapping(value="/api/v1/query?query=up{device=\"${device}\"}",
                method = RequestMethod.GET) String 
getLastPosting(@PathVariable("device") String device);

Response:

There was an unexpected error (type=Internal Server Error, status=500). content: Method Not Allowed

Any ideas about the right format?

Aba
  • 1
  • @RequestMapping(value = "/api/v1/query/{device}", method = RequestMethod.GET) What are your parameters plz clear. – Shivam Apr 27 '18 at 07:00
  • do you absolutely need this format ? can't you use `api/v1/query?query=up&device=Device_1` for example? or even `api/v1/query/up/device/Device_1` ? – Bentaye Apr 27 '18 at 08:47

1 Answers1

0

This URL really looks very strange, also these braces would be a source of error in an URL, they would need to be replaced by %7B and %7D

I think you would be better off using a simpler one such as, for example:

api/v1/query?query=up&device=Device_1

And then declare your controller this way:

@RequestMapping(value="/api/v1/query", method = RequestMethod.GET) 
public String getLastPosting(@RequestParam(value="query") String query, 
                             @RequestParam(value="device") String device) {
}

Other options would be using Unicode for curly braces (but I don't recommend these)

/api/v1/query=up%7Bdevice="Device_1"%7D

@RequestMapping(value="/api/v1/{query}",method = RequestMethod.GET)
public String getLastPosting2(@PathVariable("query") String query){

  // query is query=up{device="Device_1"}
  // you would need to parse it to extract the device name

}

or

/api/v1/query=up%7Bdevice="Device_1"%7D

@RequestMapping(value="/api/v1/query",method = RequestMethod.GET)
public String getLastPosting3(@RequestParam("query") String query){

  // query is up{device="Device_1"}
  // you would need to parse it to extract the device name

}
Bentaye
  • 9,403
  • 5
  • 32
  • 45