Go / Golang Examples – Health Fitness API¶
Access Health Fitness API in your Go applications using the standard net/http package. Both GET and POST requests are supported.
1. GET Request Example¶
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. POST Request Example¶
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))
}
Other Languages¶
Explore how to integrate Health Fitness API in other programming languages:
Start integrating Health Fitness API into your Go apps today!
Health Fitness API Powering modern digital health infrastructure