views:

57

answers:

2

I have a web application written mostly in Java. There are a few users that hope to use ruby to tailor this application to suit their own needs. How would I write an API that allows Ruby developers to interact with my application?

I'm really looking for some direction here - I know it's a broad question..

+1  A: 

You could write up a simple web service using JRuby + Rails.

Learn more about JRuby here: http://jruby.org/

The main advantage of using JRuby is that you will be able to leverage your existing Java code. The main advantage of using Ruby on Rails is that developing a web service will be a painless, even pleasurable experience.

And if you design your API in a RESTful manner, you can have Ruby programmers consume your API using ActiveResource

Resources:

  • Quick intro to JRuby on Rails: 120 second guide.
  • Great book if you want to get started: Ola Bini's Book
rmk
I think rails might be overkill for this particular problem. :-)
Benson
+1  A: 

I think rmk has the right idea here, but I think rails is overkill. You've really got two feasible options:

The first option would be to leverage JRuby to allow them to provide JRE classes that you can interface with your code. They can write classes in ruby, compile them with JRuby, and you can deploy them with your app.

The other viable option would be to create a restful API using your existing java codebase and let them consume your api from ruby, much like rmk suggests. If you're providing a restful api, there's no need to add the overhead of jruby and rails unless you have some desire to.

Benson
Thanks for the reply. And this restful API would be in Java? Do you have a suggestion as to where I could look to begin learning to do this in accordance with a best practice?
anxiety
And to clarify, a restful API does sound like what I'm looking for..
anxiety
I can recommend httparty (http://github.com/jnunemaker/httparty) for consuming the REST api on the Ruby side.The implementation of the RESTful api much depends on what framework are you using on the Java side, if any. Can you expand on this, to get more meaningful answers?
Chubas
I'm actually not using a framework on the java side.
anxiety
Yes, you would write the restful API in java. Depending on what kind of functionality you want to expose, it would be pretty simple to provide. Honestly, the reason restful APIs are so popular is because they are easy to implement and consume; the protocol does a lot of the work for you.
Benson