Reputation: 61
How to develop a REST Webservice method which accepts multiple URIs for example
If we have a method
@RequestMapping(/add)
public Response add(@RequestParam List elements){
}
The method above serves for URL https://local host:8080/add
I have asked in interview how do we have a single Webservice which serves multiple URIs which I was not able to answer as I thought we should have unique URIs for each method
A follow up to this how do we have a method which returns the format whatever choosen (JSON, XML, PLAIN TEXT) from postman client.
Upvotes: 0
Views: 165
Reputation: 244
For the first question there is many ways to do that Spring restTemplate can allow you to call a rest service in another method so all you have to do is to call your rest service when another uri is requested You can also use proxies (web server proxies) to map same webservice to many URIs
For the second one you need to pass format as parameter and call specific service linked to format when executing
Hope that helps
Upvotes: 0
Reputation: 795
Modify URI:
@RequestMapping(value = "/", produces = {
MediaType.APPLICATION_JSON_VALUE,
MediaType.APPLICATION_XML_VALUE
})
public Response add(@RequestParam List elements){
}
Upvotes: 1