← كل الأدلة

البدء السريع: أول استدعاء لواجهة MotoGP API

اشترك في RapidAPI وأرسل ترويستين واقرأ ترتيب بطولة MotoGP الحالي باستخدام curl أو JavaScript أو Python.

5 دقائق قراءة

يأخذك هذا الدليل من الصفر إلى طلب يعمل في نحو خمس دقائق. تحتاج إلى حساب على RapidAPI وإلى طرفية.

1. اشترك وانسخ مفتاحك

  1. افتح MotoGP API على RapidAPI واختر خطة.
  2. في ساحة التجربة (playground) في RapidAPI، انسخ قيمة X-RapidAPI-Key. يعرّف هذا المفتاح اشتراكك، وتحتسب RapidAPI حصتك بناءً عليه.

احفظ المفتاح في متغير بيئة بدلًا من لصقه في الشيفرة:

export RAPIDAPI_KEY="paste-your-key-here"

2. أرسل أول طلب

يحتاج كل طلب إلى ترويستين: مفتاحك ومضيف الواجهة.

curl -s "https://motogp-api-championship-data-statistics.p.rapidapi.com/standings/seasons/2026/riders?category=MOTOGP" \
  -H "X-RapidAPI-Key: $RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: motogp-api-championship-data-statistics.p.rapidapi.com"

الاستجابة هي بطولة السائقين لموسم 2026 في MotoGP، مرتبة بحسب المركز:

{
  "data": [
    {
      "position": 1,
      "total_points": 365,
      "wins": 6,
      "podiums": 6,
      "season_year": 2026,
      "rider_name": "Marc Márquez",
      "rider_number": 93,
      "team_name": "Ducati Lenovo Team",
      "category": "MOTOGP"
    }
  ],
  "meta": { "total": 32, "page": null, "size": null, "total_pages": null }
}

3. لا تكتب الموسم يدويًا في الشيفرة

يعيد GET /seasons/latest أحدث موسم، فتستمر شيفرتك بالعمل عند بدء بطولة جديدة. اربطه باستدعاء الترتيب:

JavaScript (Node.js 18+)

const HOST = "motogp-api-championship-data-statistics.p.rapidapi.com";
const headers = {
  "X-RapidAPI-Key": process.env.RAPIDAPI_KEY,
  "X-RapidAPI-Host": HOST,
};

async function get(path) {
  const res = await fetch(`https://${HOST}${path}`, { headers });
  const body = await res.json();
  if (!res.ok) throw new Error(`${res.status} ${body.message ?? res.statusText}`);
  return body.data;
}

const season = await get("/seasons/latest");
const standings = await get(`/standings/seasons/${season.year}/riders?category=MOTOGP`);

for (const row of standings.slice(0, 5)) {
  console.log(`${row.position}. ${row.rider_name} (#${row.rider_number}) – ${row.total_points} pts`);
}

Python

import os
import requests

HOST = "motogp-api-championship-data-statistics.p.rapidapi.com"
HEADERS = {"X-RapidAPI-Key": os.environ["RAPIDAPI_KEY"], "X-RapidAPI-Host": HOST}


def get(path: str, **params):
    res = requests.get(f"https://{HOST}{path}", headers=HEADERS, params=params, timeout=10)
    res.raise_for_status()
    return res.json()["data"]


season = get("/seasons/latest")
standings = get(f"/standings/seasons/{season['year']}/riders", category="MOTOGP")

for row in standings[:5]:
    print(f"{row['position']}. {row['rider_name']} (#{row['rider_number']}) – {row['total_points']} pts")

المخرجات:

1. Marc Márquez (#93) – 365 pts
2. Jorge Martín (#89) – 355 pts
3. Marco Bezzecchi (#72) – 315 pts
...

الخطوات التالية

الدليل التالي → الاصطلاحات: الغلاف والفئات والترقيم والأخطاء