Tuesday, August 10, 2010

RestEasy on GoogleAppEngine: CoreREST

I've been quite busy the last couple of months, with a lot of meetings and customer calls, so far the time to study, to create and researching is becoming rare, activities that I love are becoming less frequent day by day. I have a particular viewing of video games: I hate all them and I hate invitations to play with, I prefer play soccer for real, but in my spare time, between an airport and other, I decided give myself another chance to enjoy Ruby, and to discover why lots of people says so good things about that. So I combined a plenty of subjects that I really enjoy: JAX-RS with RestEasy, JSF2.0 (Sorry, I know a lot of people prefers GWT) and Google AppEngine. The result combination was an open project called: CoreRest (http://corerest.appspot.com)

CoreREST, is a kind of "PaaS"(Platform as a Service), which runs on Google AppEngine, which allows users to create their own lightweight "WebServices" based on REST approach using Groovy, and as sooner as possible with Ruby(powered by JRuby). I also will add many out-of-the-box APIs, such as: Smooks, and XStream, thus will possible: Transform, Convert and create really rich Services.

I used RestEasy 2.0, the JBoss implementation for JAX-RS standard, led by Bill Burke, which runs smoothly on Google AppEngine. I also, decided use another JEE6 standard in GAE: JSF 2.0, which to be honest: Without Seam, JSF seems to be a "Barbacue without salt", but in the end, it is running pretty well.

For persistence, as Google uses BigTable, a noSQL Implementation, the JPA Provider recommended by Google I really didn't liked, so I am using Objectify, which for me was more pleasant and easy to use.

In this first blog entry, I will just let you create and expose a basic "Service" in CoreRest. To do that, see the following instructions:

1- Open http://corerest.appspot.com

2- Click on Groovy logo icon

3 - Fill the following information:

3.1 - Script Name: This is the script name, which will be a kind of "endpoint name", so it will be the key for service invocation, put any simple name for it, your name for instance.

3.2 - URL Mapping - This is the URI that you want for for your service, you will put: /{firstname}/{lastname} .

3.4 - And the Source, will be the groovy script:

String response = lastname.toUpperCase() + ", "+ firstname;
return response;

3.5 - Click on "Save Script"


Well, what is happening behind the scenes:

a) the URI is the extension for the "endpoint name", and the location where you will add the variables, exactly as you do according the standard on JAX-RS. In the URL: /{firstname}/{lastname}, we will have 2 variables available for Scripting context, besides the variable "response", which is the variable to return the response as a String, although CoreRest will support some Media types, I am still working on it, once it is totally possible using RestEasy.

To test you script, you just may call you service according the following URL:

http://corerest.appspot.com/service - (Service is the ROOT for endpoints)


Next Steps:
I will try work on it, improve the UI and the user experience. I would like to say thanks to eXo Platform, for the Groovy Syntax hightlight, and Alexandre Porcelli that helped me to not use Java Regular Expressions and make my code easier :), and Eder Magalhães that tested CoreRest with me last night.

I sooner I get this code not so dirty though, I will publish and let it opensource somewhere, maybe GitHub, once I could at least to do my first commit there without any error :).

No comments: