> ## Documentation Index
> Fetch the complete documentation index at: https://www.diadata.org/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

<AccordionGroup>
  <Accordion title="Shell">
    ### cURL

    ```bash theme={"system"}
    curl --request GET \
      --url https://api.diadata.org/v1/assetQuotation/Bitcoin/0x000000000000000000000000000000000000000 \
      --header 'Content-Type: application/json'
    ```

    ### HTTPie

    ```bash theme={"system"}
    http GET https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000 \
      Content-Type:application/json
    ```

    ### Wget

    ```bash theme={"system"}
    wget --quiet \
      --method GET \
      --header 'Content-Type: application/json' \
      --output-document \
      - https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000
    ```
  </Accordion>

  <Accordion title="JavaScript">
    ### Fetch

    ```js theme={"system"}
    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

    ```js theme={"system"}
    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

    ```js theme={"system"}
    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

    ```js theme={"system"}
    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);
    });
    ```
  </Accordion>

  <Accordion title="Node">
    ### Native

    ```js theme={"system"}
    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

    ```js theme={"system"}
    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

    ```js theme={"system"}
    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

    ```js theme={"system"}
    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

    ```js theme={"system"}
    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);
    });
    ```
  </Accordion>

  <Accordion title="Python">
    ### Python 3

    ```python theme={"system"}
    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

    ```python theme={"system"}
    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)
    ```
  </Accordion>

  <Accordion title="Go">
    ```go theme={"system"}
    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))

    }
    ```
  </Accordion>

  <Accordion title="C">
    ```c theme={"system"}
    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);
    ```
  </Accordion>

  <Accordion title="Obj-C">
    ```c theme={"system"}
    #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];
    ```
  </Accordion>

  <Accordion title="OCaml">
    ```ocaml theme={"system"}
    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 *)
    ```
  </Accordion>

  <Accordion title="C#">
    ### HttpClient

    ```csharp theme={"system"}
    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

    ```csharp theme={"system"}
    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);
    ```
  </Accordion>

  <Accordion title="Java">
    ### AsyncHttp

    ```java theme={"system"}
    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

    ```java theme={"system"}
    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

    ```java theme={"system"}
    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

    ```java theme={"system"}
    HttpResponse<String> response = Unirest.get("https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000")
      .header("Content-Type", "application/json")
      .asString();
    ```
  </Accordion>

  <Accordion title="Http">
    ```bash theme={"system"}
    GET /v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000 HTTP/1.1
    Content-Type: application/json
    Host: api.diadata.org
    ```
  </Accordion>

  <Accordion title="Clojure">
    ```clojure theme={"system"}
    (require '[clj-http.client :as client])

    (client/get "https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000" {:headers {:Content-Type "application/json"}})
    ```
  </Accordion>

  <Accordion title="Kotlin">
    ```kotlin theme={"system"}
    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()
    ```
  </Accordion>

  <Accordion title="PHP">
    ### pecl/http 1

    ```php theme={"system"}
    <?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 theme={"system"}
    <?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 theme={"system"}
    <?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;
    }
    ```
  </Accordion>

  <Accordion title="Powershell">
    ### WebRequest

    ```powershell theme={"system"}
    $headers=@{}
    $headers.Add("Content-Type", "application/json")
    $response = Invoke-WebRequest -Uri 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000' -Method GET -Headers $headers
    ```

    ### RestMethod

    ```powershell theme={"system"}
    $headers=@{}
    $headers.Add("Content-Type", "application/json")
    $response = Invoke-RestMethod -Uri 'https://api.diadata.org/v1/assetQuotation/Bitcoin/0x0000000000000000000000000000000000000000' -Method GET -Headers $headers
    ```
  </Accordion>

  <Accordion title="R">
    ```r theme={"system"}
    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")
    ```
  </Accordion>

  <Accordion title="Ruby">
    ```ruby theme={"system"}
    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
    ```
  </Accordion>

  <Accordion title="Swift">
    ```swift theme={"system"}
    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()
    ```
  </Accordion>
</AccordionGroup>
