Page cover

🏁API Request's

Examples of Request Forms to the Hercai API of Some Programming Languages;

πŸ–₯️ Shell

curl --request GET \
  --url 'https://hercai.onrender.com/v3/hercai?question=hi how are you?' \
  --header 'authorization: your_apikey' \
  --header 'content-type: application/json'

πŸ”΅ Go

package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {
	url := "https://hercai.onrender.com/v3/hercai?question=hi how are you?"
	req, _ := http.NewRequest("GET", url, nil)
	
	req.Header.Add("content-type", "application/json")
	req.Header.Add("authorization", "your_apikey")
	res, _ := http.DefaultClient.Do(req)
	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))
}

🟒 NodeJS

import axios from 'axios'; // const axios = require('axios').default; For CommonJS

(async() => {
var api = await axios.get(
`https://hercai.onrender.com/v3/hercai?question=`+encodeURI("hi how are you="),{
    headers: {
        "content-type": "application/json",
        "Authorization": "your_apikey"
    },
})
console.log(api.data)
});

🟑 JavaScript

var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://hercai.onrender.com/v3/hercai?question=hi how are you?");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("authorization", "your_apikey");

xhr.send(data);

β˜• Java

HttpResponse<String> response = Unirest.get("https://hercai.onrender.com/v3/hercai?question=hi how are you?")
  .header("content-type", "application/json")
  .header("authorization", "your_apikey")
  .asString();

πŸ”΅πŸŸ‘ Python

import requests

api = requests.get(
f"https://hercai.onrender.com/v3/hercai?question=" + requests.utils.quote("hi how are you?"),
headers={"content-type": "application/json","Authorization": "your_apikey"},
            )
print(api.json())

πŸ”· PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://hercai.onrender.com/v3/hercai?question=hi how are you?",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "authorization: your_apikey",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Last updated

Was this helpful?