Skip to content
Browse files

Add groovy template

  • Loading branch information...
1 parent d61dbd9 commit 99dd26c780cdbf8340e317ff13611bb7850745c8 @abtris abtris committed Feb 4, 2014
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>

0 comments on commit 99dd26c

Please sign in to comment.
Something went wrong with that request. Please try again.