Go / Golang Beispiele – Health Fitness API¶
Greifen Sie über das Standardpaket net/http auf die Health Fitness API in Ihren Go-Anwendungen zu. Sowohl GET- als auch POST-Anfragen werden unterstützt.
1. Beispiel für eine GET-Anfrage¶
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
apiKey := "YOUR_API_KEY"
url := "https://api.hefitapi.com/api/v1/bmi?height=178&weight=82&units=metric&lang=en"
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
}
req.Header.Add("X-API-Key", apiKey)
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
2. Beispiel für eine POST-Anfrage¶
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
apiKey := "YOUR_API_KEY"
url := "https://api.hefitapi.com/api/v1/bmi/post"
payload := []byte(`{"height":178,"weight":82,"units":"metric"}`)
client := &http.Client{}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
if err != nil {
panic(err)
}
req.Header.Add("X-API-Key", apiKey)
req.Header.Add("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
Andere Sprachen¶
Erfahren Sie, wie Sie die Health Fitness API in anderen Programmiersprachen integrieren können:
Beginnen Sie noch heute mit der Integration der Health Fitness API in Ihre Go-Apps!
Health Fitness API Ermöglicht die moderne digitale Gesundheitsinfrastruktur