Aller au contenu

Exemples React Native / Expo – API Santé et Fitness

Accédez à l'API Santé et Fitness dans vos applications React Native / Expo en utilisant fetch ou axios. Les deux méthodes fonctionnent de manière transparente pour les requêtes GET et POST.


1. Utilisation de fetch

Exemple de requête 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));

Exemple de requête 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. Utilisation de axios

Tout d'abord, installez axios :

npm install axios
# or
yarn add axios

Exemple de requête 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));

Exemple de requête 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));

Autres Langues

Découvrez comment intégrer l'API Santé et Fitness dans d'autres langages de programmation :

Commencez à intégrer l'API Santé et Fitness dans vos applications mobiles et web dès aujourd'hui !


API Santé et Fitness Alimenter les infrastructures numériques de santé modernes