INNER CODE UNIT · Python
build_fetch_js
Far-Se/tabame · plugins/api-client/main.py:292
def build_fetch_js(entry):
headers = dict(entry.get("headers") or {})
auth_type = entry.get("authType", "none")
auth = entry.get("auth") or {}
if auth_type == "bearer" and auth.get("token"):
headers["Authorization"] = f"Bearer {auth['token']}"
elif auth_type == "basic":
token = base64.b64encode(
f"{auth.get('user', '')}:{auth.get('pass', '')}".encode()
).decode()
headers["Authorization"] = f"Basic {token}"
opts = {"method": entry.get("method", "GET"), "headers": headers}
body_type = entry.get("bodyType", "none")
if body_type == "json" and entry.get("body"):
opts["body"] = entry["body"]
headers.setdefault("Content-Type", "application/json")
elif body_type == "text" and entry.get("body"):
opts["body"] = entry["body"]