React Native / Expo の例 – ヘルス&フィットネス API¶
React Native / Expo アプリ で Health Fitness API を 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 をインストールします:
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));
その他の言語¶
Health Fitness API の統合方法を他のプログラミング言語で探求してください:
今日から、Health Fitness API をモバイルおよび Web アプリに統合しましょう!
Health Fitness API 最新のデジタルヘルスインフラを支える