> For the complete documentation index, see [llms.txt](https://docs.airqo.net/airqo-rest-api-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.airqo.net/airqo-rest-api-documentation/guidelines/code-samples.md).

# Code Samples

## Javascript

```
const apiUrl = 'YOUR_API_ENDPOINT';
fetch(apiUrl)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));
```

[JavaScript Sample Code GitHub Repository](https://github.com/airqo-platform/code-samples/tree/staging/javascript)

## PHP

```
<?php
// Sample PHP code
$apiUrl = 'YOUR_API_ENDPOINT';
$response = file_get_contents($apiUrl);
$data = json_decode($response, true);
print_r($data);
?>
```

[PHP Sample Code GitHub Repository](https://github.com/airqo-platform/code-samples/tree/staging/php)

## Python

```
# Sample Python code
import requests

api_url = 'YOUR_API_ENDPOINT'
response = requests.get(api_url)
data = response.json()
print(data)

```

[Python Sample Code GitHub Repository](https://github.com/airqo-platform/code-samples/tree/staging/python)

## Java

```
// Sample Java code
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ApiRequest {
  public static void main(String[] args) {
    try {
      String apiUrl = "YOUR_API_ENDPOINT";
      URL url = new URL(apiUrl);
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.setRequestMethod("GET");

      BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      String line;
      StringBuilder response = new StringBuilder();

      while ((line = reader.readLine()) != null) {
        response.append(line);
      }
      reader.close();

      System.out.println(response.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

```

[Java Sample Code GitHub Repository](https://github.com/airqo-platform/code-samples/tree/staging/java)

## Go

Explore the power of Go with our Air Quality API. This code sample demonstrates how to interact with our endpoints using Go, providing a seamless integration experience for your applications.

```
// Import necessary packages
import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {
	// Define API endpoint
	apiEndpoint := "https://api.airqo.net/v2/your-endpoint-path"

	// Make a GET request to the API
	resp, err := http.Get(apiEndpoint)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	defer resp.Body.Close()

	// Read the response body
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Error reading response:", err)
		return
	}

	// Display the API response
	fmt.Println("API Response:", string(body))
}

```

[Go Sample Code GitHub Repository](https://github.com/airqo-platform/code-samples/tree/staging/go)

## Dart

Leverage Dart's simplicity and efficiency with our Air Quality API. This code sample showcases how to utilize Dart for seamless integration with our API, offering a smooth development experience for your projects.

```
import 'dart:convert';
import 'package:http/http.dart' as http;

void main() async {
  // Define API endpoint
  var apiEndpoint = 'https://api.airqo.net/v2/your-endpoint-path';

  // Make a GET request to the API
  var response = await http.get(Uri.parse(apiEndpoint));

  // Decode and display the API response
  var jsonResponse = json.decode(response.body);
  print('API Response: $jsonResponse');
}

```

[Dart Sample Code GitHub Repository](https://github.com/airqo-platform/code-samples/tree/staging/dart)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.airqo.net/airqo-rest-api-documentation/guidelines/code-samples.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
