简体   繁体   English

Ruby中的Java兼容REST客户端

[英]Java compatible REST client in Ruby

I need to create a client library to access a REST-based web service via HTTPS. 我需要创建一个客户端库,以通过HTTPS访问基于REST的Web服务。

Not being overly familiar with Java, I would like to do this in Ruby, and then compile to a jar. 不太熟悉Java,我想在Ruby中进行此操作,然后编译为jar。

The payload I will send will be (in JSON) something like: 我将发送的有效载荷将是(以JSON形式):

{
  "api-token": "12345",
  "org_number": 5,
  "name": "ABC corp",
  "users": {
    "employee_number": 1,
    "name": "bob jones",
    "email": "bob@abc.com"
  }
}

I assume the client library will need to: 我认为客户端库将需要:

  • Initialize a new API interface instance with API token 使用API​​令牌初始化新的API接口实例
  • Give the instance organization information and set of users 提供实例组织信息和用户集
  • Tell the instance to serialize the organization and users to JSON, and POST to the webservice /org/new 告诉实例将组织和用户序列化为JSON,然后发布到webservice / org / new

So my question is: 所以我的问题是:

Have you considered JRuby? 您考虑过JRuby吗?

https://github.com/jruby/jruby/wiki https://github.com/jruby/jruby/wiki

Have u heard of ApiClient ? 您听说过ApiClient吗?

It works well inside rails, making your controller as much thin as possible. 它在导轨内部运行良好,从而使控制器尽可能地薄。 But it also works on a non rails application. 但它也可以在非Rails应用程序上使用。

It raises different exceptions for each type of http code response to make easy for u to control the client logic based on the server responses. 对于每种类型的http代码响应,它都会引发不同的异常,从而使u可以轻松地基于服务器响应来控制客户端逻辑。

It automatically initializes an object using the api response for you and sends all the requests by json as well. 它会使用api响应自动为您初始化一个对象,并通过json发送所有请求。

It still in development, so let me know of any feature u may need. 它仍在开发中,所以让我知道您可能需要的任何功能。

I use it to access an API which requires a token for OAUTH2 and it works pretty well so far. 我使用它来访问API,该API需要OAUTH2的令牌,并且到目前为止效果很好。

Hope u enjoy. 希望你喜欢。 =) =)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM