I have a Java JAX-RS REST service which has many endpoints, let's say:
...
POST /api/ops/create
GET /api/items
...
Both of them served under same war file, so if I want to reach them from a client I am using following URLs:
POST http://server.domain.com:8080/the_war_file/api/ops/create
POST http://server.domain.com:8080/the_war_file/api/items
Well, the question begins here. I want to access the GET endpoint from the code behind the POST endpoint.
In other words, I want to send a GET request when I am operating the POST request.
Of course, I can send the request to the full URL with server, port and name of the war file. However, it seems wrong, because I am already in the war file.
Or, I know I can call the method of the other endpoint directly. Is it rational?
So, are there any efficient methods/solutions to call different endpoint in the same war file? (Like routing etc.)
CodePudding user response:
I know I can call the method of the other endpoint directly. Is it rational?
Yes, this is perfectly fine where in your code behind one request you will call a method of some class that is used for serving some other request. There is no need to send extra HTTP request unless you have a specific need for invocation of that method to be triggered by HTTP request