انتقل إلى المحتوى

أمثلة React Native / Expo – واجهة برمجة تطبيقات الصحة واللياقة البدنية

استخدم واجهة برمجة تطبيقات الصحة واللياقة البدنية في تطبيقات React Native / Expo الخاصة بك باستخدام fetch أو axios. كلا الطريقتين تعملان بسلاسة مع طلبات GET و POST.


1. باستخدام fetch

مثال لطلب GET:

const apiKey = "YOUR_API_KEY";
const url = "https://api.hefitapi.com/api/v1/bmi?height=178&weight=82&units=metric&lang=en";

fetch(url, {
  method: "GET",
  headers: {
    "X-API-Key": apiKey
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error("Error:", error));

مثال لطلب POST:

const apiKey = "YOUR_API_KEY";
const url = "https://api.hefitapi.com/api/v1/bmi/post";

const payload = {
  height: 178,
  weight: 82,
  units: "metric"
};

fetch(url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": apiKey
  },
  body: JSON.stringify(payload)
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error("Error:", error));

2. باستخدام axios

أولاً، قم بتثبيت axios:

npm install axios
# or
yarn add axios

مثال لطلب GET:

import axios from "axios";

const apiKey = "YOUR_API_KEY";
const url = "https://api.hefitapi.com/api/v1/bmi?height=178&weight=82&units=metric&lang=en";

axios.get(url, { headers: { "X-API-Key": apiKey } })
  .then(response => console.log(response.data))
  .catch(error => console.error("Error:", error));

مثال لطلب POST:

import axios from "axios";

const apiKey = "YOUR_API_KEY";
const url = "https://api.hefitapi.com/api/v1/bmi/post";

const payload = { height: 178, weight: 82, units: "metric" };

axios.post(url, payload, { headers: { "X-API-Key": apiKey } })
  .then(response => console.log(response.data))
  .catch(error => console.error("Error:", error));

لغات أخرى

استكشف كيفية دمج واجهة برمجة تطبيقات الصحة واللياقة البدنية في لغات برمجة أخرى:

ابدأ في دمج واجهة برمجة تطبيقات الصحة واللياقة البدنية في تطبيقاتك المحمولة والويب اليوم!


واجهة برمجة تطبيقات الصحة واللياقة البدنية تمكين البنية التحتية الرقمية الحديثة للصحة