Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #10 from abtris/abtris/groovy

Add groovy template
  • Loading branch information...
commit 343ff917cb7930ca811e44fd10d1dde9e7863a26 2 parents b5dbbbd + 99dd26c
@Almad Almad authored
Showing with 45 additions and 0 deletions.
  1. +45 −0 groovy.html
View
45 groovy.html
@@ -0,0 +1,45 @@
+<section name="groovy" class="groovy">
+<p class="ioDesc">Request</p>
+<pre class="incoming"><code class="language-groovy"><% headerFirst = true %><%= "import groovyx.net.http.RESTClient\n
+import static groovyx.net.http.ContentType.JSON\nimport groovy.json.JsonSlurper\nimport groovy.json.JsonOutput\n\n" %>
+<% eos = "<<<EOT\n" %>
+@Grab (group = 'org.codehaus.groovy.modules.http-builder', module = 'http-builder', version = '0.5.0')
+def client = new RESTClient("<%= @apiUrl %>")
+
+<% if @method is 'HEAD': %>
+response = client.head( path : "<%= @url %>" )
+<% end %>
+<% if @method is 'GET': %>
+response = client.get( path : "<%= @url %>" )
+<% end %>
+<% if @method is 'DELETE': %>
+response = client.delete( path : "<%= @url %>" )
+<% end %>
+<% if @method is 'POST': %>
+def jsonObj = new JsonSlurper().parseText('<%= @body %>')
+response = client.post( path : "<%= @url %>",
+ body : jsonObj,
+ <% if @contentType.toLowerCase() is 'application/json': %>
+contentType : JSON )
+ <% else: %>
+contentType : ANY )
+ <% end %>
+<% end %>
+<% if @method is 'PUT': %>
+def jsonObj = new JsonSlurper().parseText('<%= @body %>')
+response = client.put( path : "<%= @url %>",
+ body : jsonObj,
+ <% if @contentType.toLowerCase() is 'application/json': %>
+contentType : JSON )
+ <% else: %>
+contentType : ANY )
+ <% end %>
+<% end %>
+
+println("Status:" + response.status)
+if (response.data) {
+ println("Content Type: " + response.contentType)
+ println("Body:\n" + JsonOutput.prettyPrint(JsonOutput.toJson(response.data)))
+}
+</code></pre>
+</section>
Please sign in to comment.
Something went wrong with that request. Please try again.