Install
pip install httpx
API key
import os
import httpx
BASE = os.environ.get("HOJ_API_BASE", "https://sandbox.api.hofj.com")
API_KEY = os.environ["HOJ_API_KEY"]
with httpx.Client(base_url=BASE, timeout=30.0) as client:
r = client.get(
"/v1/products",
params={"limit": 10, "brand": "Weebora", "locale": "it"},
headers={"Authorization": f"Bearer {API_KEY}"},
)
r.raise_for_status()
data = r.json()
print(data["data"])
OAuth2
import httpx
def fetch_token(base: str, client_id: str, client_secret: str) -> str:
with httpx.Client(base_url=base) as client:
r = client.post(
"/v1/oauth/token",
data={
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret,
},
headers={"Content-Type": "application/x-www-form-urlencoded"},
)
r.raise_for_status()
return r.json()["access_token"]
Async variant
Usehttpx.AsyncClient for FastAPI, asyncio workers, or high concurrency crawlers.
