简体   繁体   English

我有REST API,并想重用它以在同一服务器上公开不同格式的API

[英]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: 另一种方式:

  1. I use Tomcat. 我使用Tomcat。 Push my request directly to tomcat somehow. 以某种方式直接将我的请求推送到tomcat。
  2. I use Guice, and all requests go through GuiceFilter. 我使用Guice,并且所有请求都通过GuiceFilter。 Craft ServetRequest, ServletResponce and FilterChain objects and directly call GuiceFilter.doFilter. 制作ServetRequest,ServletResponce和FilterChain对象,然后直接调用GuiceFilter.doFilter。
  3. I use GuiceContainer for Jersey. 我将GuiceContainer用于球衣。 Some test frameworks use it for REST API testing, but also need to craft request/response objects. 一些测试框架将其用于REST API测试,但还需要构建请求/响应对象。

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.

相关问题 我已经从API的JSON格式中获取了文本,现在我想从我的android应用中的同一API向其添加图像 - I have taken text from JSON format of an API now I want to add image to it from same API in my android app 我可以在Rest Api中为两个班级使用相同的路径吗? - Can i have the same path for two classes in Rest Api? 在不同的服务器上创建相同的会话 - Create same session on differen server 使用Spring Data REST将基本CustomRepository方法公开给REST API - Exposing base CustomRepository method to REST API using Spring Data REST 服务器上的格式化日期来自REST API的响应不起作用 - Format Date on Server Response from REST API not working 在 REST API 调用之后,我有以下格式的键/值对,我只需要提取与键对应的特定值 - After REST API call ,i have key/value pair in the below format ,I Need to extract just the specific value corresponding to the key 我想从java中的REST API返回XML格式的响应 - I want to return response in XML form from REST API in java 我想'插入XML并在Rest API中提供对象 - I want to 'pase xml and serve objects in rest api 泽西岛-Rest API(Json格式) - Jersey - Rest API (Json Format) REST API的推荐日期格式 - Recommended date format for REST API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM