API Request Samples
To simplify your DIA API integration journey, we created sample API calls for retrieving price data in the most widely used programming languages.
All examples make a call to DIA Asset Quotation API for Bitcoin price.
Shell
cURL
curl --request GET \
--url https://api.diadata.org/v1/assetQuotation/Bitcoin/0x000000000000000000000000000000000000000 \
--header 'Content-Type: application/json'
HTTPie
http GET https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000 \
Content-Type:application/json
Wget
wget --quiet \
--method GET \
--header 'Content-Type: application/json' \
--output-document \
- https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000
JavaScript
Fetch
fetch("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000", {
"method": "GET",
"headers": {
"Content-Type": "application/json"
}
})
.then(response => {
console.log(response);
})
.catch(err => {
console.error(err);
});
XMLHttpRequest
const data = null;
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
jQuery
const settings = {
"async": true,
"crossDomain": true,
"url": "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000",
"method": "GET",
"headers": {
"Content-Type": "application/json"
}
};
$.ajax(settings).done(function (response) {
console.log(response);
});
Axios
import axios from "axios";
const options = {
method: 'GET',
url: 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000',
headers: {'Content-Type': 'application/json'}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
Node
Native
const http = require("https");
const options = {
"method": "GET",
"hostname": "api.diadata.org",
"port": null,
"path": "/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000",
"headers": {
"Content-Type": "application/json"
}
};
const req = http.request(options, function (res) {
const chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
Request
const request = require('request');
const options = {
method: 'GET',
url: 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000',
headers: {'Content-Type': 'application/json'}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
Unirest
const unirest = require("unirest");
const req = unirest("GET", "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000");
req.headers({
"Content-Type": "application/json"
});
req.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.body);
});
Fetch
const fetch = require('node-fetch');
let url = 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000';
let options = {method: 'GET', headers: {'Content-Type': 'application/json'}};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
Axios
var axios = require("axios").default;
var options = {
method: 'GET',
url: 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000',
headers: {'Content-Type': 'application/json'}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
Python
Python 3
import http.client
conn = http.client.HTTPSConnection("api.diadata.org")
headers = { 'Content-Type': "application/json" }
conn.request("GET", "/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Requests
import requests
url = "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"
headers = {'Content-Type': 'application/json'}
response = requests.request("GET", url, headers=headers)
print(response.text)
Go
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
C
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
CURLcode ret = curl_easy_perform(hnd);
Obj-C
#import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"Content-Type": @"application/json" };
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];
OCaml
open Cohttp_lwt_unix
open Cohttp
open Lwt
let uri = Uri.of_string "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000" in
let headers = Header.add (Header.init ()) "Content-Type" "application/json" in
Client.call ~headers `GET uri
>>= fun (res, body_stream) ->
(* Do stuff with the result *)
C#
HttpClient
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"),
Headers =
{
{ "Content-Type", "application/json" },
},
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}
RestSharp
var client = new RestClient("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000");
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
Java
AsyncHttp
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepare("GET", "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")
.setHeader("Content-Type", "application/json")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();
client.close();
NetHttp
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"))
.header("Content-Type", "application/json")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
OkHttp
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")
.get()
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Unirest
HttpResponse<String> response = Unirest.get("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")
.header("Content-Type", "application/json")
.asString();
Http
GET /v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000 HTTP/1.1
Content-Type: application/json
Host: api.diadata.org
Clojure
(require '[clj-http.client :as client])
(client/get "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000" {:headers {:Content-Type "application/json"}})
Kotlin
val client = OkHttpClient()
val request = Request.Builder()
.url("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")
.get()
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()
PHP
pecl/http 1
<?php
$request = new HttpRequest();
$request->setUrl('https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000');
$request->setMethod(HTTP_METH_GET);
$request->setHeaders([
'Content-Type' => 'application/json'
]);
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
pecl/http 2
<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000');
$request->setRequestMethod('GET');
$request->setHeaders([
'Content-Type' => 'application/json'
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
cURL
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Powershell
WebRequest
$headers=@{}
$headers.Add("Content-Type", "application/json")
$response = Invoke-WebRequest -Uri 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000' -Method GET -Headers $headers
RestMethod
$headers=@{}
$headers.Add("Content-Type", "application/json")
$response = Invoke-RestMethod -Uri 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000' -Method GET -Headers $headers
R
library(httr)
url <- "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000"
response <- VERB("GET", url, add_headers(Content_Type = 'application/json'), content_type("application/octet-stream"))
content(response, "text")
Ruby
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["Content-Type"] = 'application/json'
response = http.request(request)
puts response.read_body
Swift
import Foundation
let headers = ["Content-Type": "application/json"]
let request = NSMutableURLRequest(url: NSURL(string: "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()