cURLNode.jsPythonPHPJavaC#GoRuby
cURL
curl --get 'https://api.soccersapi.com/v2.2/fixtures/' \
--data-urlencode "user=$SOCCERSAPI_USER" \
--data-urlencode "token=$SOCCERSAPI_TOKEN" \
--data-urlencode 't=info' \
--data-urlencode 'id=2589310' \
--data-urlencode 'include=events,stats'
Node.js
const url = new URL('https://api.soccersapi.com/v2.2/fixtures/');
url.search = new URLSearchParams({
user: process.env.SOCCERSAPI_USER,
token: process.env.SOCCERSAPI_TOKEN,
t: 'info',
id: '2589310',
include: 'events,stats',
});
const response = await fetch(url);
if (!response.ok) throw new Error(`SoccersAPI ${response.status}`);
const body = await response.json();
console.log(body.data);
Python
import os
import requests
response = requests.get(
"https://api.soccersapi.com/v2.2/fixtures/",
params={
"user": os.environ["SOCCERSAPI_USER"],
"token": os.environ["SOCCERSAPI_TOKEN"],
"t": "info",
"id": 2589310,
"include": "events,stats",
},
timeout=15,
)
response.raise_for_status()
print(response.json()["data"])
PHP
<?php
$query = http_build_query([
'user' => getenv('SOCCERSAPI_USER'),
'token' => getenv('SOCCERSAPI_TOKEN'),
't' => 'info',
'id' => '2589310',
'include' => 'events,stats',
]);
$curl = curl_init("https://api.soccersapi.com/v2.2/fixtures/?$query");
curl_setopt_array($curl, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15]);
$body = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);
if ($status !== 200) throw new RuntimeException("SoccersAPI $status");
print_r(json_decode($body, true)['data']);
Java
var query = "user=" + URLEncoder.encode(System.getenv("SOCCERSAPI_USER"), UTF_8)
+ "&token=" + URLEncoder.encode(System.getenv("SOCCERSAPI_TOKEN"), UTF_8)
+ "&t=info&id=2589310&include=events%2Cstats";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.soccersapi.com/v2.2/fixtures/?" + query))
.GET()
.build();
var response = HttpClient.newHttpClient().send(request, BodyHandlers.ofString());
if (response.statusCode() != 200) throw new IOException("SoccersAPI " + response.statusCode());
System.out.println(response.body());
C#
using var client = new HttpClient();
var query = new Dictionary<string, string?> {
["user"] = Environment.GetEnvironmentVariable("SOCCERSAPI_USER"),
["token"] = Environment.GetEnvironmentVariable("SOCCERSAPI_TOKEN"),
["t"] = "info",
["id"] = "2589310",
["include"] = "events,stats",
};
var url = "https://api.soccersapi.com/v2.2/fixtures/?" +
string.Join("&", query.Select(x => $"{x.Key}={Uri.EscapeDataString(x.Value ?? "")}"));
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Go
endpoint, _ := url.Parse("https://api.soccersapi.com/v2.2/fixtures/")
query := endpoint.Query()
query.Set("user", os.Getenv("SOCCERSAPI_USER"))
query.Set("token", os.Getenv("SOCCERSAPI_TOKEN"))
query.Set("t", "info")
query.Set("id", "2589310")
query.Set("include", "events,stats")
endpoint.RawQuery = query.Encode()
response, err := http.Get(endpoint.String())
if err != nil { log.Fatal(err) }
defer response.Body.Close()
if response.StatusCode != http.StatusOK { log.Fatalf("SoccersAPI %s", response.Status) }
io.Copy(os.Stdout, response.Body)
Ruby
uri = URI('https://api.soccersapi.com/v2.2/fixtures/')
uri.query = URI.encode_www_form(
user: ENV.fetch('SOCCERSAPI_USER'),
token: ENV.fetch('SOCCERSAPI_TOKEN'),
t: 'info',
id: 2_589_310,
include: 'events,stats'
)
response = Net::HTTP.get_response(uri)
raise "SoccersAPI #{response.code}" unless response.is_a?(Net::HTTPSuccess)
puts JSON.parse(response.body).fetch('data')
The interactive reference generates additional clients from the same OpenAPI operation. Always remove credentials before pasting a generated request into a ticket, chat or public repository.