From 8922f7e5bfb8288ed9655b3114b1756164f8c533 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Noli Villar Date: Mon, 18 Jun 2018 14:24:21 -0300 Subject: [PATCH 1/2] Added an example to make a post I think this example will be very useful for other people. I tried a lot of ways until I realized this was the correct way of posting a json with variable keys. --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 23e7560..7280b55 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,15 @@ And XML: In the example above the `auth` method performs HTTP basic auth, the `contentType` method sets the content type, and the `json` method constructs a JSON body. +Another example for posting a JSON with variable keys + + def map = [key_1: value_1, key_2: value_2, ...., key_n:value_n] + def resp = rest.put("http://repo.grails.org/grails/api/security/groups/test-group"){ + auth System.getProperty("artifactory.user"), System.getProperty("artifactory.pass") + json { map } + } + + ### A `POST` with URL parameters def resp = rest.post('http://someServer/foo/bar?username={username}&password={password}') { From 7cc93d9feef8740070ec13941940fb68d13106c2 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Noli Villar Date: Mon, 18 Jun 2018 14:25:47 -0300 Subject: [PATCH 2/2] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 7280b55..983722d 100644 --- a/README.md +++ b/README.md @@ -59,8 +59,7 @@ In the example above the `auth` method performs HTTP basic auth, the `contentTyp Another example for posting a JSON with variable keys def map = [key_1: value_1, key_2: value_2, ...., key_n:value_n] - def resp = rest.put("http://repo.grails.org/grails/api/security/groups/test-group"){ - auth System.getProperty("artifactory.user"), System.getProperty("artifactory.pass") + def resp = rest.post("http://repo.grails.org/grails/api/security/groups/test-group"){ json { map } }