I have an endpoint that I need to call from a method inside of a class.
public void remove(String str) {
//Call Controller with str
}
The controller has /local/{str}
. How do I call this controller from that method?
I have an endpoint that I need to call from a method inside of a class.
public void remove(String str) {
//Call Controller with str
}
The controller has /local/{str}
. How do I call this controller from that method?
So I suppose that your controller is similar to this
@GetMapping("/local/{str}")
public String method(@PathVariable String str) {...}
Why not to call this method directly?
public void remove(String str) {
method("my parameter");
}
Or you can also call this endpoint by using RestTemplate
public void remove(String str) {
final String uri = "http://hostName/local/{str}";
Map<String, String> params = new HashMap<String, String>();
params.put("str", "my_String");
RestTemplate restTemplate = new RestTemplate();
String response = restTemplate.getForObject(uri, String.class, params);
}