Zum Inhalt

React Native / Expo Beispiele – Health Fitness API

Greifen Sie über fetch oder axios auf die Health Fitness API in Ihren React Native / Expo Apps zu. Beide Methoden funktionieren nahtlos für GET- und POST-Anfragen.


1. Verwendung von fetch

Beispiel für eine GET-Anfrage:

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));

Beispiel für eine POST-Anfrage:

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. Verwendung von axios

Installieren Sie zunächst axios:

npm install axios
# or
yarn add axios

Beispiel für eine GET-Anfrage:

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));

Beispiel für eine POST-Anfrage:

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));

Weitere Sprachen

Entdecken Sie, wie Sie die Health Fitness API in anderen Programmiersprachen integrieren können:

Beginnen Sie noch heute, die Health Fitness API in Ihren mobilen und Web-Anwendungen zu integrieren!


Health Fitness API Ermöglicht moderne digitale Gesundheitsinfrastruktur