In an effort to bring the expressiveness of ruby and the REST frameworks in Java, Charles Nutter makes the case for delevoping RESTful services using JRuby+Rails. He observes the inherent thought leadership in the Ruby and Rails communities in building RESTful applications that leverage the web.

[…] Rubyists have been helping to lead the way, building restfulness into just about everything they write. Rails itself is built around REST, with most controllers doubling as RESTful interfaces, and it even provides extra tools to help you transparently make RESTful calls from your application. If you're doing RESTful services for a typical Ruby application, Rails is the way to go.

To demonstrate the ability to define a RESTful service in JRuby, he surveys the solution landscape for libraries and frameworks for building RESTful services in Java. He starts with a simple example service using the standard JAX-RS API

I followed the Jersey Getting Started tutorial using Ruby for everything (and not using Maven in this case). My version of their HelloWorldResource looks like this in Ruby:

He describes the internals of how the ruby class gets compiled and the internals of the in memory representation of the object.

Under the covers, this class will load in the source of our restful_service.rb file and wire up all the Ruby and Java pieces so that both sides see HelloWorld as the in-memory representation of the Ruby HelloWorld class. Method calls are dispatched to the Ruby code, constructors dispatch to initialize, and so on. It's truly living in both worlds.
With the service in hand, we now need a server script to start it up.

He proceeds to deal with the notoriously-hard-to-get-right CLASSPATH so that the example can run.

I've tossed them into my CLASSPATH env var, but you're free to do it however you like

He concludes with a call for “examples of other nice annotation-based APIs we could test out with JRuby?” Do share interesting examples in the forum and visit the original post for details on writing RESTful services in JRuby.

Is your profile up-to-date? Please take a moment to review and update.

Email Address

Note: If updating/changing your email, a validation request will be sent

Company name:

Keep current company name

Update Company name to:

Company role:

Keep current company role

Update company role to:

Company size:

Keep current company Size

Update company size to:

Country/Zone:

Keep current country/zone

Update country/zone to:

State/Province/Region:

Keep current state/province/region

Update state/province/region to:

Subscribe to our newsletter?

Subscribe to our architect newsletter?

Subscribe to our industry email notices?

You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.