Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top