### Fetch Rugby Leagues using Node.js with Unirest Source: https://api-sports.io/documentation/rugby/v1/index This example uses the Unirest library in Node.js to make a GET request to the rugby leagues API. It includes the API key in the request headers and logs the raw response body. The 'unirest' package needs to be installed. ```javascript var unirest = require('unirest'); var req = unirest('GET', 'https://v1.rugby.api-sports.io/leagues') .headers({ 'x-apisports-key': 'XxXxXxXxXxXxXxXxXxXxXxXx', }) .end(function (res) { if (res.error) throw new Error(res.error); console.log(res.raw_body); }); ``` -------------------------------- ### GET /odds Source: https://api-sports.io/documentation/rugby/v1/index Retrieve odds for a specific rugby game. The example demonstrates how to make a GET request to the /odds endpoint with query parameters and headers. ```APIDOC ## GET /odds ### Description Retrieves odds for a specific rugby game. ### Method GET ### Endpoint `/odds` ### Query Parameters - **game** (string) - Required - The ID of the game for which to retrieve odds. ### Headers - **x-apisports-key** (string) - Required - Your API key. ### Request Example ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.rugby.api-sports.io/odds'); $request->setRequestMethod('GET'); $request->setQuery(new http\QueryString(array( 'game' => '1107' ))); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` ### Response #### Success Response (200) - **response** (object) - Contains the odds data for the specified game. ``` -------------------------------- ### Get Seasons List (Ruby) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available seasons using the API-Sports Rugby v1 API with Ruby. Requires an x-apisports-key header. ```ruby require 'net/http' require 'uri' uri = URI.parse('https://v1.rugby.api-sports.io/seasons') request = Net::HTTP::Get.new(uri) request['x-apisports-key'] = 'XxXxXxXxXxXxXxXxXxXxXxXx' response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end puts response.body ``` -------------------------------- ### Fetch Rugby Leagues Data (Example) Source: https://api-sports.io/documentation/rugby/v1/index This set of code examples demonstrates how to fetch data for rugby leagues using the API. Replace `{endpoint}` with the desired endpoint (e.g., 'leagues', 'games') and `XxXxXxXxXxXxXxXxXxXxXx` with your actual API key. These examples cover common programming languages and illustrate the basic structure of an API request. ```cURL curl --request GET \ --url 'https://v1.rugby.api-sports.io/leagues' \ --header 'x-apisports-key: XxXxXxXxXxXxXxXxXxXxXx' ``` ```javascript const axios = require('axios'); const options = { method: 'GET', url: 'https://v1.rugby.api-sports.io/leagues', headers: { 'x-apisports-key': 'XxXxXxXxXxXxXxXxXxXxXx' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.log(error); }); ``` ```php "https://v1.rugby.api-sports.io/leagues", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-apisports-key: XxXxXxXxXxXxXxXxXxXxXx" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #: " . $err; } else { echo $response; } ?> ``` ```python import requests url = "https://v1.rugby.api-sports.io/leagues" headers = { 'x-apisports-key': "XxXxXxXxXxXxXxXxXxXxXx" } response = requests.request("GET", url, headers=headers) print(response.text) ``` -------------------------------- ### Fetch Rugby Leagues using Go and net/http Source: https://api-sports.io/documentation/rugby/v1/index Provides a Go example for retrieving rugby league data using the native `net/http` package. It constructs an HTTP GET request, adds the API key to the headers, sends the request, and reads the response body. Error handling is included for request creation and response reading. This code is self-contained and requires no external libraries beyond the Go standard library. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://v1.rugby.api-sports.io/leagues" method := "GET" client := &http.Client { } req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } req.Header.Add("x-apisports-key", "XxXxXxXxXxXxXxXxXxXxXxXx") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Fetch Rugby Leagues using Node.js with Axios Source: https://api-sports.io/documentation/rugby/v1/index Demonstrates fetching rugby league data using the Axios library in Node.js. Requires the 'axios' package to be installed. It sends a GET request to the leagues endpoint with the API key in the headers and logs the response data or any errors. ```javascript var axios = require('axios'); var config = { method: 'get', url: 'https://v1.rugby.api-sports.io/leagues', headers: { 'x-apisports-key': 'XxXxXxXxXxXxXxXxXxXxXxXx', } }; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); }); ``` -------------------------------- ### Generic Endpoint Example (e.g., Leagues) Source: https://api-sports.io/documentation/rugby/v1/index This example demonstrates how to call a generic endpoint like 'leagues'. Replace '{endpoint}' with the desired endpoint name and ensure your API key is included in the header. ```APIDOC ## GET /{endpoint} ### Description Retrieves data for a specified Rugby endpoint (e.g., leagues, games). Replace `{endpoint}` with the actual endpoint name. ### Method GET ### Endpoint `/{endpoint}` ### Parameters #### Path Parameters - **endpoint** (string) - Required - The specific API endpoint to call (e.g., `leagues`, `games`, `teams`). #### Query Parameters None specified in documentation, but may be available depending on the specific endpoint. #### Request Body None ### Request Example ```bash curl -X GET "https://v1.rugby.api-sports.io/leagues" \ -H "x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx" ``` ### Response #### Success Response (200) - The response structure will vary based on the specific endpoint called. Consult the API documentation for detailed response schemas for each endpoint. #### Response Example (for /leagues) ```json { "get": "leagues", "parameters": [], "errors": [], "results": 10, "response": [ { "league": { "id": 15, "name": "Super Rugby Pacific", "type": "league", "logo": "https://media.api-sports.io/rugby/leagues/15.png" }, "country": { "id": 8, "name": "Australia", "code": "AU", "flag": "https://media.api-sports.io/flags/au.svg" }, "seasons": [ { "year": 2023, "start": "2023-02-23", "end": "2023-06-24", "current": true, "coverage": 1 } ] } // ... more league objects ] } ``` ``` -------------------------------- ### Fetch Rugby Leagues using Javascript (Fetch API) Source: https://api-sports.io/documentation/rugby/v1/index An example using the browser's built-in Fetch API in Javascript to get rugby league data. It constructs a GET request with the API key in the headers and logs the response text to the console or any errors encountered. This method is widely supported in modern web browsers. ```javascript var myHeaders = new Headers(); myHeaders.append("x-apisports-key", "XxXxXxXxXxXxXxXxXxXxXxXx"); var requestOptions = { method: 'GET', headers: myHeaders, redirect: 'follow' }; fetch("https://v1.rugby.api-sports.io/leagues", requestOptions) .then(response => response.text()) .then(result => console.log(result)) .catch(error => console.log('error', error)); ``` -------------------------------- ### Get Seasons List (PHP) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available seasons using the API-Sports Rugby v1 API with PHP. Requires an x-apisports-key header. ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.rugby.api-sports.io/seasons'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Get Timezone List (Ruby) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available timezones using the API-Sports Rugby v1 API with Ruby. Requires an x-apisports-key header. ```ruby require 'net/http' require 'uri' uri = URI.parse('https://v1.rugby.api-sports.io/timezone') request = Net::HTTP::Get.new(uri) request['x-apisports-key'] = 'XxXxXxXxXxXxXxXxXxXxXxXx' response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end puts response.body ``` -------------------------------- ### Fetch Rugby Leagues using cURL Source: https://api-sports.io/documentation/rugby/v1/index A simple command-line example using cURL to fetch rugby league data. This command specifies the GET request method, the API endpoint URL, and includes the API key in the request headers. This is useful for quick testing or integration into shell scripts. ```bash curl --request GET \ --url https://v1.rugby.api-sports.io/leagues \ --header 'x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx' ``` -------------------------------- ### Fetch Rugby Leagues using PHP with cURL Source: https://api-sports.io/documentation/rugby/v1/index This PHP example uses the cURL extension to make a GET request to the rugby leagues API. It sets various cURL options, including the API key in the headers, and outputs the response body. This method is suitable for servers with cURL enabled. ```php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://v1.rugby.api-sports.io/leagues', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx', ), )); $response = curl_exec($curl); curl_close($curl); echo $response; ``` -------------------------------- ### Custom Translation JSON Example Source: https://api-sports.io/documentation/rugby/v1/index An example of the JSON structure required for custom translations. This format allows developers to override default widget labels, translate missing terms, and adapt terminology for specific audiences. ```json { "all": "All", "live": "Now Live", "finished": "Completed", "scheduled": "Coming Up", "favorites": "Favorites" } ``` -------------------------------- ### Get Seasons List (JavaScript) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available seasons using the API-Sports Rugby v1 API with JavaScript (using fetch API). Requires an x-apisports-key header. ```javascript fetch('https://v1.rugby.api-sports.io/seasons', { method: 'GET', headers: { 'x-apisports-key': 'XxXxXxXxXxXxXxXxXxXxXxXx' } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Get Countries List (Ruby) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available countries using the API-Sports Rugby v1 API with Ruby. Supports filtering by id, name, code, and search. Requires an x-apisports-key header. ```ruby require 'net/http' require 'uri' uri = URI.parse('https://v1.rugby.api-sports.io/countries') request = Net::HTTP::Get.new(uri) request['x-apisports-key'] = 'XxXxXxXxXxXxXxXxXxXxXxXx' response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end puts response.body ``` -------------------------------- ### Fetch Rugby Leagues using Javascript (XHR) Source: https://api-sports.io/documentation/rugby/v1/index An example using the XMLHttpRequest (XHR) object in Javascript to retrieve rugby league data. It sets up an event listener for state changes, configures the GET request with the API endpoint and key, and sends the request. The response text is logged when the request is complete. This is a more traditional approach compared to Fetch. ```javascript var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function() { if(this.readyState === 4) { console.log(this.responseText); } }); xhr.open("GET", "https://v1.rugby.api-sports.io/leagues"); xhr.setRequestHeader("x-apisports-key", "XxXxXxXxXxXxXxXxXxXxXxXx"); xhr.send(); ``` -------------------------------- ### Get Countries List (PHP) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available countries using the API-Sports Rugby v1 API with PHP. Supports filtering by id, name, code, and search. Requires an x-apisports-key header. ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.rugby.api-sports.io/countries'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Fetch Rugby Leagues using PHP with Http Source: https://api-sports.io/documentation/rugby/v1/index This PHP code utilizes the 'http' package to retrieve rugby league data. It sets up a GET request with the API key and sends it using the http client, then echoes the response body. This library needs to be installed. ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.rugby.api-sports.io/leagues'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Fetch Rugby Leagues using PHP with Request2 Source: https://api-sports.io/documentation/rugby/v1/index This PHP snippet uses the HTTP_Request2 PEAR package to fetch rugby league data. It configures a GET request with the API key and handles potential exceptions, printing the response body if successful. Ensure the HTTP_Request2 package is installed. ```php setUrl('https://v1.rugby.api-sports.io/leagues'); $request->setMethod(HTTP_Request2::METHOD_GET); $request->setConfig(array( 'follow_redirects' => TRUE )); $request->setHeader(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx', )); try { $response = $request->send(); if ($response->getStatus() == 200) { echo $response->getBody(); } else { echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' . $response->getReasonPhrase(); } } catch(HTTP_Request2_Exception $e) { echo 'Error: ' . $e->getMessage(); } ``` -------------------------------- ### Get Rugby Head-to-Head Games (PHP Example) Source: https://api-sports.io/documentation/rugby/v1/index This PHP code snippet demonstrates how to make a request to the API-SPORTS Rugby API to get head-to-head (h2h) game data between two teams. It includes setting the URL, method, query parameters, and headers, including the required API key. ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.rugby.api-sports.io/games/h2h'); $request->setRequestMethod('GET'); $request->setQuery(new http\QueryString(array( 'h2h' => '367-368' ))); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Fetch Rugby Leagues using Shell (Httpie & wget) Source: https://api-sports.io/documentation/rugby/v1/index Provides examples for retrieving league data from the API Sports Rugby v1 API using command-line tools Httpie and wget. Both methods require the 'x-apisports-key' header. ```shell http --follow --timeout 3600 GET 'https://v1.rugby.api-sports.io/leagues' \ x-apisports-key:'XxXxXxXxXxXxXxXxXxXxXxXx' \ ``` ```shell wget --no-check-certificate --quiet \ --method GET \ --timeout=0 \ --header 'x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx' \ 'https://v1.rugby.api-sports.io/leagues' ``` -------------------------------- ### Fetch Rugby Leagues using C and libcurl Source: https://api-sports.io/documentation/rugby/v1/index Demonstrates how to fetch rugby league data using the C programming language with the libcurl library. It initializes a curl handle, sets the URL to the API endpoint, configures request headers including the API key, and performs the request. Ensure libcurl is installed and linked. ```c CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_URL, "https://v1.rugby.api-sports.io/leagues"); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https"); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); res = curl_easy_perform(curl); } curl_easy_cleanup(curl); ``` -------------------------------- ### Get Seasons List (Curl) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available seasons using the API-Sports Rugby v1 API with Curl. Requires an x-apisports-key header. ```bash curl --request GET \ --url 'https://v1.rugby.api-sports.io/seasons' \ --header 'x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx' ``` -------------------------------- ### Widget Usage and Configuration Source: https://api-sports.io/documentation/rugby/v1/index Demonstrates how to use the api-sports-widget with various attributes for data type, API key, sport selection, and dynamic targeting. ```APIDOC ## API Sports Widgets API Sports provides widgets that can be integrated into your website to display sports data. These widgets can be configured using various data attributes. ### Widget Attributes - **`data-type`** (string) - Required - Specifies the type of widget to display (e.g., `games`, `game`, `team`, `player`, `standings`, `league`, `leagues`, `h2h`, `races`, `race`, `driver`, `fights`, `fight`, `fighter`). - **`data-key`** (string) - Required - Your API key for authentication. - **`data-sport`** (string) - Optional - Specifies the sport for which to retrieve data (e.g., `football`, `basketball`). Defaults to the sport associated with the widget type if not specified. - **`data-lang`** (string) - Optional - Sets the interface language for the widget. Available options: `en`, `fr`, `es`, `it`. Defaults to `en`. - **`data-custom-lang`** (string) - Optional - URL to a custom JSON file for language translations. This allows for overriding default translations or providing missing ones. Custom translations take priority over `data-lang`. - **`data-target-*`** (string) - Optional - Used for dynamic targeting, specifying where a widget opened by another widget should be rendered. Options include `modal` or a CSS selector (e.g., `#details`, `.container`). The specific attribute name depends on the sport and widget type (e.g., `data-target-game`, `data-target-standings`, `data-target-race`). - **`data-show-errors`** (boolean) - Optional - If set to `true`, error messages will be displayed within the widget and in the browser console for debugging purposes. ### Example 1: Basic Game Widget with Element Targeting This example displays a list of games and targets a `div` with the ID `details` to render game details when clicked. ```html
``` ### Example 2: Game Widget Targeting a Modal This example displays a list of games and configures game details to open in a modal window. ```html ``` ### Example 3: Language and Custom Translation This example demonstrates setting the language to English and providing a URL for custom translations. ```html ``` ### Example 4: Custom Translation Example This example uses a custom language setting and points to a custom translation file. ```html ``` ### Caching Implementing a caching system is highly recommended to reduce API request volume. Widgets can cache responses for a specified duration (e.g., 60 seconds), serving subsequent requests from the cache instead of hitting the API directly. This can drastically reduce daily request counts. ### Debugging To enable debugging, set the `data-show-errors` attribute to `true`. This will display error messages within the widget and in the browser console, which can help identify issues such as exceeding daily request limits, incorrect tags, or an invalid API key. ``` -------------------------------- ### Get Timezone List (Curl) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available timezones using the API-Sports Rugby v1 API with Curl. Requires an x-apisports-key header. ```bash curl --request GET \ --url 'https://v1.rugby.api-sports.io/timezone' \ --header 'x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx' ``` -------------------------------- ### Get Timezone List (Node.js) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available timezones using the API-Sports Rugby v1 API with Node.js. Requires an x-apisports-key header. ```javascript // Node.js example would typically use a library like 'axios' or 'node-fetch' // Placeholder for Node.js implementation. ``` -------------------------------- ### Targeting Widget Content via Modal Source: https://api-sports.io/documentation/rugby/v1/index Illustrates the use of the 'data-target-game' attribute set to 'modal' to display widget content within a modal popup. This is useful for presenting detailed information without disrupting the main page layout. ```html ``` -------------------------------- ### Get Timezone List (PHP) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available timezones using the API-Sports Rugby v1 API with PHP. Requires an x-apisports-key header. ```php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://v1.rugby.api-sports.io/timezone'); $request->setRequestMethod('GET'); $request->setHeaders(array( 'x-apisports-key' => 'XxXxXxXxXxXxXxXxXxXxXxXx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` -------------------------------- ### Fetch Rugby Leagues using PowerShell Source: https://api-sports.io/documentation/rugby/v1/index Demonstrates fetching league data from the API Sports Rugby v1 API using PowerShell's Invoke-RestMethod. Requires the 'x-apisports-key' header. ```powershell $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("x-apisports-key", "XxXxXxXxXxXxXxXxXxXxXxXx") $response = Invoke-RestMethod 'https://v1.rugby.api-sports.io/leagues' -Method 'GET' -Headers $headers $response | ConvertTo-Json ``` -------------------------------- ### Setting Widget Interface Language Source: https://api-sports.io/documentation/rugby/v1/index Shows how to configure the display language for widgets using the 'data-lang' attribute. It also includes an example of how to use 'data-custom-lang' to load a custom translation file for further customization, with custom translations taking precedence. ```html ``` -------------------------------- ### Get Timezone List (JavaScript) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available timezones using the API-Sports Rugby v1 API with JavaScript (using fetch API). Requires an x-apisports-key header. ```javascript fetch('https://v1.rugby.api-sports.io/timezone', { method: 'GET', headers: { 'x-apisports-key': 'XxXxXxXxXxXxXxXxXxXxXxXx' } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Fetch Rugby Leagues using Java and Unirest Source: https://api-sports.io/documentation/rugby/v1/index Demonstrates fetching rugby league data in Java using the Unirest library. This snippet makes a GET request to the API endpoint, setting the API key in the request headers. The response is captured as a String. Ensure Unirest is included as a dependency in your project. ```java Unirest.setTimeouts(0, 0); HttpResponse response = Unirest.get("https://v1.rugby.api-sports.io/leagues") .header("x-apisports-key", "XxXxXxXxXxXxXxXxXxXxXxXx") .asString(); ``` -------------------------------- ### Get Countries List (Curl) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available countries using the API-Sports Rugby v1 API with Curl. Supports filtering by id, name, code, and search. Requires an x-apisports-key header. ```bash curl --request GET \ --url 'https://v1.rugby.api-sports.io/countries' \ --header 'x-apisports-key: XxXxXxXxXxXxXxXxXxXxXxXx' ``` -------------------------------- ### Get Countries List (JavaScript) Source: https://api-sports.io/documentation/rugby/v1/index Example of fetching the list of available countries using the API-Sports Rugby v1 API with JavaScript (using fetch API). Supports filtering by id, name, code, and search. Requires an x-apisports-key header. ```javascript fetch('https://v1.rugby.api-sports.io/countries', { method: 'GET', headers: { 'x-apisports-key': 'XxXxXxXxXxXxXxXxXxXxXxXx' } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Apply Custom CSS Theme to Widget Source: https://api-sports.io/documentation/rugby/v1/index Demonstrates how to define custom CSS variables to style an api-sports-widget and how to apply this custom theme using the 'data-theme' attribute. ```css api-sports-widget[data-theme="MyTheme"] { --primary-color: #18cfc0; --success-color: #2ecc58; --warning-color: #f39c12; --danger-color: #e74c3c; --light-color: #898989; --home-color: var(--primary-color); --away-color: #ffc107; --text-color: #333; --text-color-info: #333; --background-color: #fff; --primary-font-size: 0.72rem; --secondary-font-size: 0.75rem; --button-font-size: 0.8rem; --title-font-size: 0.9rem; --header-text-transform: uppercase; --button-text-transform: uppercase; --title-text-transform: uppercase; --border: 1px solid #95959530; --game-height: 2.3rem; --league-height: 2.35rem; --score-size: 2.25rem; --flag-size: 22px; --teams-logo-size: 18px; --teams-logo-size-xl: 5rem; --hover: rgba(200, 200, 200, 0.15); } ``` -------------------------------- ### Fetch Rugby Leagues using Ruby (Net::HTTP) Source: https://api-sports.io/documentation/rugby/v1/index Illustrates how to fetch league data from the API Sports Rugby v1 API using Ruby's built-in Net::HTTP library. This method requires specifying the 'x-apisports-key' header. ```ruby require 'uri' require 'net/http' require 'openssl' url = URI("https://v1.rugby.api-sports.io/leagues") 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["x-apisports-key"] = 'XxXxXxXxXxXxXxXxXxXxXxXx' response = http.request(request) puts response.read_body ``` -------------------------------- ### Fetch Rugby Leagues using Swift (URLSession) Source: https://api-sports.io/documentation/rugby/v1/index Demonstrates how to fetch league data from the API Sports Rugby v1 API using Swift's URLSession. This involves creating a URLRequest, adding the 'x-apisports-key' header, and executing the task. ```swift import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif var semaphore = DispatchSemaphore (value: 0) var request = URLRequest(url: URL(string: "https://v1.rugby.api-sports.io/leagues")!,timeoutInterval: Double.infinity) request.addValue("XxXxXxXxXxXxXxXxXxXxXxXx", forHTTPHeaderField: "x-apisports-key") request.httpMethod = "GET" let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data else { print(String(describing: error)) semaphore.signal() return } print(String(data: data, encoding: .utf8)!) semaphore.signal() } task.resume() semaphore.wait() ```