simplicityitself / grails-gwt

New Grails GWT Plugin
Other
23 stars 18 forks source link

Rest instead of RPC #32

Closed confile closed 10 years ago

confile commented 10 years ago

You wrote a nice interface to integrate GWT RPC calls into Grails. Have you any idea how to use this with GWTP REST (see: http://simplicityitself.github.io/grails-gwt/guide/3.%20Server%20RPC.html )

I think this would be a great extension to your plugin and I suppose it is very similar. Can you help me with that?

confile commented 10 years ago

here is the link to GWTP REST: https://github.com/ArcBees/GWTP/wiki/Rest-Dispatch

daviddawson commented 10 years ago

The GWTP examples show jaxws and jaxrs being used on the server side to expose soap and REST endpoints.

There is a Grails plugin for jaxws at http://grails.org/plugins/tag/jaxws and one for jaxrs/ REST at http://grails.org/plugin/jaxrs

I would suggest using one of those plugins as they are already focused on auto exposing services via http/ rpc or rest endpoints.

This kind of functionality is best served in a seperate project rather than being integrated into the gwt plugin. If there's something that could be made nicer in one of those plugins that is GWT specific (like the explicit support for DTO plugin that currently exists), then that would be a good addition.

For now though, I recommend trying that and seeing how it works out for you.

On other applications, I've implemented REST endpoints in the Grails controller layer, which works well enough for many applications.

confile commented 10 years ago

@daviddawson Thanks for your recommendations. Would you mind to post an example for your Grails Rest service?

I am very new in Grails/GWT. I could not figure out how I set an URLMapping to a service?

daviddawson commented 10 years ago

On the server side, probably best to go through the docs, Grails has good support for REST built into the framework.

http://grails.org/doc/latest/guide/webServices.html#REST

This describes setting up REST using the domain classes directly and using controllers as rest end points. I'd recommend going for one of these.

confile commented 10 years ago

@daviddawson I read that but I see a problem. When I access a controller that handles a rest service. I think that a session is created. Isn't that a problem since I might get a new session for each request?

daviddawson commented 10 years ago

In Grails, sessions, in common with all java servlet based frameworks, are only created when they are asked for. So the solution is to not access the session in your code, and then one won't be created.

You're moving more into 'how do I create a best practice rest service in grails' territory, rather than GWT specific. I suggest you consult with the grails user mailing list to get the best recommendations.

confile commented 10 years ago

@daviddawson thank you very much for help