We present a sample code, that allows you to get the current rate of the EURUSD currency pair. Looking for more examples? See our API Documentation.
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.xchangeapi.com/json/currencies/EURUSD"
method := "GET"
payload := strings.NewReader("")
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
}
req.Header.Add("api-key", "your-api-key")
res, err := client.Do(req)
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
import requests
url = "https://api.xchangeapi.com/json/currencies/EURUSD"
payload = {}
headers = {
'api-key': 'your-api-key'
}
response = requests.request("GET", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
var data = "";
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://api.xchangeapi.com/json/currencies/EURUSD?api-key=your-api-key");
xhr.send(data);
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://api.xchangeapi.com/json/currencies/EURUSD',
'headers': {
'api-key': 'your-api-key'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.xchangeapi.com/json/currencies/EURUSD",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"api-key: your-api-key"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url("https://api.xchangeapi.com/json/currencies/EURUSD")
.method("GET", null)
.addHeader("api-key", "your-api-key")
.build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"
url = URI("https://api.xchangeapi.com/json/currencies/EURUSD")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"
response = http.request(request)
puts response.read_body