[英]I have REST API and want to reuse it for exposing differen format API on same server
I implemented and exposed REST API on my server. 我在服务器上实现并公开了REST API。 Now I need to expose same API, but I can't use REST (it's actually websocket messages), it will be some custom format.
现在,我需要公开相同的API,但是我不能使用REST(实际上是websocket消息),它将是一些自定义格式。 Don't ask why )
不要问为什么)
I imagine message transformation from my custom format to http request, then process it in my web-server, transform response back to my custom format, and send to client. 我想象消息将从我的自定义格式转换为http请求,然后在Web服务器中对其进行处理,将响应转换回我的自定义格式,然后发送给客户端。
The simplest way is regular http call to localhost. 最简单的方法是对localhost的常规http调用。 For example (java):
例如(java):
HttpURLConnection con = (HttpURLConnection) new URL("http://localhost/api/...").openConnection();
and so on, or using some http client library. 等等,或者使用一些http客户端库。 But I'm afraid there will be too much overhead, creating connection, etc.
但是,恐怕会产生过多的开销,创建连接等。
Another ways: 另一种方式:
There is no standard way to craft request object at all. 根本没有制定请求对象的标准方法。 And I don't know on which level it's better to add my custom requests.
而且我不知道将我的自定义请求添加到哪个级别更好。
Hope I described my problem clearly. 希望我能清楚地描述我的问题。
Atmosphere may be a good fit here. 这里的气氛可能很合适。 It's allegedly compatible with both Resteasy and Jersey, so that's a plus, it simply adds WebSocket functionality on top of these.
据称它与Resteasy和Jersey兼容,这是一个优点,它只是在这些之上添加了WebSocket功能。
Caveat: I haven't tried this myself, but came across it when looking for the same capability. 警告:我自己没有尝试过,但是在寻找相同功能时遇到了它。 :-)
:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.