...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
Abstract
This code snippet fetches a currency conversion rateaccesses 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
Code Block | ||||
---|---|---|---|---|
| ||||
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.<id>.val } // called only for a 404 (not found) status code: response.'"404'" = { resp -> printlnreturn '"Not found'" } } |
Placeholders
Placeholder | Description | Example | |||
---|---|---|---|---|---|
<URL > | URL | http://free.currencyconverterapi.com/api/v5/convert?q=EUR_USD&compact=y | <id> | The conversion Id | EUR_USD |
Context
The outcome of the code snippet is a BigDecimal. Youdepends on the content type passed to the request method. You could use this code, for example, to convert currency from one to another.get a specific currency conversion rate.
Use cases
Reference
Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...