Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple HTTP GET request in groovy

Tags:

http

groovy

I am very newbie for this groovy programming. I have written an API which is running in my local system (localhost:2100).

Now i want to make a simple GET request to this API using groovy code. I searched a lot for this but i cant find the clear guidance.

I tried for this :

http://www.kellyrob99.com/blog/2013/02/10/groovy-and-http/ http://rest.elkstein.org/2008/02/using-rest-in-groovy.html etc.. But nothing works.

Also i came across HttpBuilder. I cant get clear idea of this. Please share your ideas.

EDIT:

I tried for this:

def client = new RESTClient("http://localhost:2100");
def res = client.get(path:"xxx/yyy/zzz")

I am receiving error:

Groovy:unable to resolve class RESTClient

Whether I need to add dependency in my pom.xml?

like image 840
Subburaj Avatar asked Oct 16 '15 05:10

Subburaj


People also ask

How do you get a response on Groovy?

Open groovy script > Right click > Get data > Select the test case step which has the API call > Select request/response etc. The "request" is type of class java. lang. String.

How do you call a URL in groovy?

URL url = new URL("http://192.168.1.87:8080/bridge/test.php"); URLConnection conn = url. openConnection();


1 Answers

If you need to do a simple GET petition. You can use the URL Class. For example, to get the content of example.org, with a GET request

new URL("http://example.org/").text
like image 167
Fernando Avatar answered Oct 05 '22 17:10

Fernando