Exemplos React Native / Expo – API de Saúde e Fitness¶
Acesse a API de Saúde e Fitness em seus aplicativos React Native / Expo usando fetch ou axios. Ambos os métodos funcionam perfeitamente para solicitações GET e POST.
1. Usando fetch¶
Exemplo de solicitação 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));
Exemplo de solicitação 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. Usando axios¶
Primeiro, instale o axios:
Exemplo de solicitação 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));
Exemplo de solicitação 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));
Outras Linguagens¶
Explore como integrar a API de Saúde e Fitness em outras linguagens de programação:
Comece a integrar a API de Saúde e Fitness em seus aplicativos móveis e web hoje mesmo!
API de Saúde e Fitness Impulsionando a infraestrutura digital de saúde moderna