0

I have a spring boot API that internally has to call another API and just "forward" the request.

private String APIRoot;
public APIInteractionController() {
        this.APIRoot = "<API root here, not showing it because it's private>";
    }
//test if calling API works
@GetMapping("/test")
public String testAPI(){
    logCallAPI(APIRoot);
    String result = callAPI(APIRoot);
    return result;
}
private String callAPI(String uri){
    RestTemplate restTemplate = new RestTemplate();
    String result = restTemplate.getForObject(uri, String.class);
    return result;
}
private void logCallAPI(String uri){
    System.out.println("call API:\nuri: " + uri);
}

When I call the endpoint on my sprig boot app, the logger statement gets outputted in the console, but in postmane I just get a 404 even though when I call the API on itself it just returns "hello world" as the root just returns a test string. Why is this, and how can I resolve this.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ArneVC
  • 5
  • 2

2 Answers2

0

This stackoverflow answer describes how to enable http wire logging for Spring RestTemplate. With this enabled, you should be able to see in your logs which URL is actually called and figure out from where, why you receive a 404 return code.

Bertolt
  • 995
  • 1
  • 13
  • 37
0

I solved the issue I was having here by adding the @ResponseBody annotation to the methods.

ArneVC
  • 5
  • 2