रिएक्ट नेटिव / एक्सपो उदाहरण – हेल्थ फिटनेस एपीआई¶
अपने रिएक्ट नेटिव / एक्सपो ऐप्स में हेल्थ फिटनेस एपीआई तक 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));
अन्य भाषाएँ¶
अन्य प्रोग्रामिंग भाषाओं में हेल्थ फिटनेस एपीआई को एकीकृत करने के बारे में जानें:
आज ही अपने मोबाइल और वेब ऐप्स में हेल्थ फिटनेस एपीआई को एकीकृत करना शुरू करें!
हेल्थ फिटनेस एपीआई आधुनिक डिजिटल स्वास्थ्य बुनियादी ढांचे को सशक्त बनाना