Code Examples¶
The following code serves as an example.
Please adapt and customize it to suit your requirements.
Example
import requests
import json
data = {
"servers": [
{
"game_id": "minecraft",
"servers": [
"192.168.0.1:25568",
"192.168.0.1:25569"
]
}
]
}
url = 'https://gamequery.dev/post/add'
headers = {
'Content-Type': 'application/json',
'x-api-token': 'TOKEN',
'x-api-token-type': 'FREE OR PRO',
'x-api-token-email': 'YOUR ACCOUNT EMAIL',
'Authorization': 'Bearer apitestoken'
}
response = requests.post(url, json=data, headers=headers)
print(response.text)
const axios = require('axios');
const data = {
servers: [
{
game_id: "minecraft",
servers: [
"192.168.0.1:25568",
"192.168.0.1:25569"
]
}
]
};
const url = 'https://gamequery.dev/post/add';
const headers = {
'Content-Type': 'application/json',
'x-api-token': 'TOKEN',
'x-api-token-type': 'FREE OR PRO',
'x-api-token-email': 'YOUR ACCOUNT EMAIL',
'Authorization': 'Bearer apitestoken'
};
axios.post(url, data, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error));
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class Main {
public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient();
String json = "{\"servers\":[{\"game_id\":\"minecraft\",\"servers\":[\"192.168.0.1:25568\",\"192.168.0.1:25569\"]}]}";
RequestBody body = RequestBody.create(json, JSON);
Request request = new Request.Builder()
.url("https://gamequery.dev/post/add")
.addHeader("Content-Type", "application/json")
.addHeader("x-api-token", "TOKEN")
.addHeader("x-api-token-type", "FREE OR PRO")
.addHeader("x-api-token-email", "YOUR ACCOUNT EMAIL")
.addHeader("Authorization", "Bearer apitestoken")
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
}
}
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://gamequery.dev/post/add")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request["x-api-token"] = "TOKEN"
request["x-api-token-type"] = "FREE OR PRO"
request["x-api-token-email"] = "YOUR ACCOUNT EMAIL"
request["Authorization"] = "Bearer apitestoken"
data = {
"servers": [
{
"game_id": "minecraft",
"servers": [
"192.168.0.1:25568",
"192.168.0.1:25569"
]
}
]
}
request.body = JSON.dump(data)
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
http.request(request)
end
puts response.body
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var data = new
{
servers = new[]
{
new
{
game_id = "minecraft",
servers = new[]
{
"192.168.0.1:25568",
"192.168.0.1:25569"
}
}
}
};
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("x-api-token", "TOKEN");
client.DefaultRequestHeaders.Add("x-api-token-type", "FREE OR PRO");
client.DefaultRequestHeaders.Add("x-api-token-email", "YOUR ACCOUNT EMAIL");
client.DefaultRequestHeaders.Add("Authorization", "Bearer apitestoken");
var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://gamequery.dev/post/add", content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
}
#include <iostream>
#include <cpprest/http_client.h>
using namespace web;
using namespace web::http;
using namespace web::http::client;
int main() {
json::value data;
data["servers"][0]["game_id"] = json::value::string(U("minecraft"));
data["servers"][0]["servers"][0] = json::value::string(U("192.168.0.1:25568"));
data["servers"][0]["servers"][1] = json::value::string(U("192.168.0.1:25569"));
http_client client(U("https://gamequery.dev/post/add"));
http_request request(methods::POST);
request.headers().set_content_type(U("application/json"));
request.headers().add(U("x-api-token"), U("TOKEN"));
request.headers().add(U("x-api-token-type"), U("FREE OR PRO"));
request.headers().add(U("x-api-token-email"), U("YOUR ACCOUNT EMAIL"));
request.headers().add(U("Authorization"), U("Bearer apitestoken"));
request.set_body(data);
client.request(request)
.then([](http_response response) {
return response.extract_string();
})
.then([](utility::string_t response_str) {
std::wcout << response_str << std::endl;
})
.wait();
return 0;
}
<?php
$data = array(
'servers' => array(
array(
'game_id' => 'minecraft',
'servers' => array(
'192.168.0.1:25568',
'192.168.0.1:25569'
)
)
)
);
$url = 'https://gamequery.dev/post/add';
$token = 'TOKEN';
$email = 'YOUR ACCOUNT EMAIL';
$tokenType = 'FREE OR PRO';
$apiToken = 'Bearer apitestoken';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'x-api-token: ' . $token,
'x-api-token-type: ' . $tokenType,
'x-api-token-email: ' . $email,
'Authorization: ' . $apiToken
));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
You can do anything; you can retrieve server information from any type of database and send those server details to our API.
Upon sending the data to the API endpoint, you will receive back comprehensive details about the servers you've specified.
This flexibility allows you to seamlessly integrate our API into your existing systems, enabling efficient retrieval of server information regardless of the database type or structure you utilize.
Note
Replace 192.168.0.1:XXXXX
with the actual IP addresses and Ports of your servers.
Generate your API token at https://gamequery.dev/api/generate and replace TOKEN
with it.