是否有任何方法可以从同一 API 调用另一个端点
我有一个 Java JAX-RS REST 服务,它有很多端点,比方说:
...
POST /api/ops/create
GET /api/items
...
它们都在同一个 war 文件下提供服务,所以如果我想从客户端访问它们,我将使用以下 URL:
POST http://server.domain.com:8080/the_war_file/api/ops/create
POST http://server.domain.com:8080/the_war_file/api/items
好吧,问题从这里开始。我想从POST端点后面的代码访问GET端点。
换句话说,我想在操作POST请求时发送GET请求。
当然,我可以将请求发送到包含服务器、端口和 war 文件名称的完整 URL。 然而,这似乎是错误的,因为我已经在war文件中了。
或者,我知道我可以直接调用另一个端点的方法。是理性的吗?
那么,是否有任何有效的方法/解决方案可以在同一个war文件中调用不同的端点? (比如路由等)
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这完全没问题,在一个请求后面的代码中,您将调用某个类的方法,该类用于服务其他请求。除非您有特定需要通过 HTTP 请求触发调用该方法,否则无需发送额外的 HTTP 请求
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