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

Version 1 Next »

Abstract

This code snippet fetches a currency conversion rate.

Logic

Initialize a new HTTPbuilder, use the common request types and get the response.

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
    reader.<id>.val
  }
 
  // called only for a 404 (not found) status code:
  response.'404' = { resp ->
    println 'Not found'
  }
}
Placeholders
PlaceholderDescriptionExample
<URL>URLhttp://free.currencyconverterapi.com/api/v5/convert?q=EUR_USD&compact=y
<id>The conversion IdEUR_USD

Context

The outcome of the code snippet is a BigDecimal. You could use this code, for example, to convert currency from one to another.

Reference

Filter by label

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

  • No labels