API key

package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	base := getenv("HOJ_API_BASE", "https://sandbox.api.hofj.com")
	key := os.Getenv("HOJ_API_KEY")
	req, _ := http.NewRequest(http.MethodGet, base+"/v1/products?limit=5&brand=Weebora&locale=it", nil)
	req.Header.Set("Authorization", "Bearer "+key)
	req.Header.Set("Accept", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)
	fmt.Println(string(body))
}

func getenv(k, def string) string {
	if v := os.Getenv(k); v != "" {
		return v
	}
	return def
}

Production hardening

  • Use a typed client, configurable timeouts (http.Client{Timeout: ...}), and retry with backoff on 429 / 502.
  • Parse RFC 7807 problem JSON on error responses (application/problem+json).