I have a controller class this way with endpoints. I know that we can access RESTful endpoints in a web application through a tool like 'postman' using the URL. But I am not sure how to access these endpoints. This is not a web application.
This is a java application deployed as a JAR on server using embedded tomcat.
How can I access these endpoints?
@Controller
public class TopicStatsController {
@Autowired
private QueueDepths depths;
@RequestMapping("/topicDepth")
@ResponseBody
public Long topicDepth() throws Exception {
return depths.topicDepth();
}
@RequestMapping("/subscribersDepth")
@ResponseBody
public List<Long> subscribersDepth() throws Exception {
return depths.subscribersDepth();
}
}
You can access the endpoints using RestTemplate .
RestTemplate restTemplate = new RestTemplate();
String fooResourceUrl
= "/topicDepth";
ResponseEntity<String> response
= restTemplate.getForEntity(fooResourceUrl + "/1", Long.class);
Your remote must be having an IP address and a port number .
You can use it to hit a GET
or POST
request.
On localhost - http://localhost:8080/myapp-oracle/api/v1/user
On remote - http://172.16.254.1:8080/myapp-oracle/api/v1/user
Note: You also need to change the http protocol depending upon the server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.