Our new Appfire Documentation Space is now live!

Take a look here! If you have any questions please email support@appfire.com

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Abstract

This code snippet accesses the REST API of a client from a Groovy script written in the Groovy editor of the add-on.

Logic

  • Import the HTTPBuilder and the required request methods.
  • Initialize a new builder and provide a URL
  • Pass the method, the content type, and the request configuration closure to the request method.
  • Handle the responses and content.

Snippet 

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.JSON
 
// initialize a new builder and give a default URL
def http = new HTTPBuilder("<URL>")
 
http.request(GET,JSON) { req ->
 
  response.success = { resp, reader ->
    assert resp.status == 200
	return reader
  }
 
  // called only for a 404 (not found) status code:
  response."404" = { resp ->
    return "Not found"
  }
}
Placeholders

Context

The outcome of the code snippet depends on the content type passed to the request method. You could use this code, for example, to get a specific currency conversion rate.

Use cases

Reference

Filter by label

There are no items with the selected labels at this time.

  • No labels