Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to do a POST web service request in Grails?

I want to do a POST request to a web service in grails, but it seems like the available JAVA solutions are on a very low abstraction level, like building the POST request myself (here is the sample I found: http://www.exampledepot.com/egs/java.net/Post.html)

Is there a better solution for this problem in Grails? I searched through the manuals and other stuff, but did not really find something. Just wondering, because normally I did not see much code like this wen developing Grails.

So if there is no other solution, then this will also be O.K., abstracted by me and hidden somewhere in our libraries, but I guess there is a better solution somewhere.

like image 490
Paul Weber Avatar asked Jun 06 '11 14:06

Paul Weber


1 Answers

There's the Groovy-specific HTTPBuilder, which provides a nice interface built on the Apache HTTPClient. It even has a REST client, if that's appropriate for the service your are trying to access. There's even a Grails plugin to wrap that all up for you.

If the service is REST-enabled there are a range of Java projects and APIs that can simplify things.

On the other hand, if the web service you are trying to access is SOAP-based, you can leverage GroovyWS, which is also wrapped in a Grails plugin available here.

I've just listed a bunch of options. What will work best depends a lot on the service you are trying to connect to. I'd recommend starting with a pre-built Grails plugin and only branching out if you find it doesn't meet your needs.

like image 153
ig0774 Avatar answered Oct 07 '22 00:10

ig0774