Take the 2-minute tour ×

I am trying to see if the built-in REST functionality that Grails ships with will allow the same Grails app to hit a RESTful API endpoint on another machine (effectively making it the REST client), as well as serving that same API endpoint so that it can be hit from other machines (effectively making it the REST server).

For instance, say I have 2 Grails apps, App A and App B. Both will expose a /ping REST endpoint, that, perhaps, returns a JSON "pong" message when hit from an HTTP GET. I am wondering if App A can hit App B's /ping endpoint, while also serving an endpoint of the same name/signature (so that App B can hit App A's /ping as well)?

Most importantly, going one step further, I'd like to abstract both RESTful client/server functionality (for /ping) out into a Grails plugin, say grails-pingrest.zip, and then have both Apps A and B import this plugin as a dependency. That way both share the same codebase for client & server implementations.

Is this possible? If so, how and are there any obstacles/caveats/gotchyas. If not, why?

share|improve this question
Entirely possible for this to happen. Using a plugin is the correct approach as well. –  Joshua Moore Apr 8 at 19:14
Thanks @JoshuaMoore (+1) - I am concerned however about port interference or just general communication issues if the same Grails app is listening on Port 8080 and serving /ping requests, as well as making requests to another machine's /ping endpoint. Any thoughts on this type of interference? –  AdjustingForInflation Apr 8 at 19:17
There won't be any interference at all. No reason at all as to why there would be. –  Joshua Moore Apr 8 at 19:27
Thanks @JoshuaMoore (+1) - but what if App A sends an outbound /ping HTTP GET to App B at the same time that App B does the same to App A? Couldn't there be contention on the port? –  AdjustingForInflation Apr 8 at 19:28
Nope, since requests are served in different threads. Even if you host the two applications on the same server they are going to be served by different threads and are still different applications. Even if they use the same plugin internally. –  Joshua Moore Apr 8 at 19:31

2 Answers 2

up vote 1 down vote accepted

You are definitely on the right path with creating a plugin with this shared functionality. You won't have any issues calling out to the same endpoint but on a different application even if the same application has the same endpoint.

someplace.com/ping and myotherplace.com/ping won't have any issues nor would domain.com/appa/ping and domain.com/appb/ping

share|improve this answer

Sounds like a webhook or an api chain. Grails API Toolkit supports both.

share|improve this answer

Your Answer


