Activiti GET/POST REST requests with Groovy

I have been working with Activiti lately and needed to test the REST API included with the demo. Below are the GET and POST requests I whipped up using Groovy. Hope you find this useful 🙂

//---Get Request
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0' )

def client = new RESTClient('http://localhost:8080/activiti-rest/service/process-engine')
println client.get(headers:[Authorization:"Basic ${'kermit:kermit'.bytes.encodeBase64()}"]).data

// output
[name:default, exception:null, version:5.7, resourceUrl:jar:file:/Users/juanvazquez/Documents/activiti-5.7/apps/apache-tomcat-6.0.32/webapps/activiti-rest/WEB-INF/lib/activiti-cfg.jar!/activiti.cfg.xml]

// POST request
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0' )
import static

def jsonObj = new groovy.json.JsonBuilder()
  userId 'kermit'
  password 'kermit'
def client = new'http://localhost:8080/activiti-rest/service/login')
def response = JSON, body:jsonObj.toString() )



2 thoughts on “Activiti GET/POST REST requests with Groovy

  1. Perfect! I’ve been looking for something just like this. Thanks!

    Out of curiosity, is it necessary to make a new RESTClient object for every method?

  2. I don’t believe it is necessary. But I am not able to test at the moment as the project that I used this code with is not currently accessible. It should be pretty easy to test in your environment. Sorry to punt on an answer.

Leave a Reply

Your email address will not be published.