import json, urllib.request, urllib.error BASE = {"tickets-api": "http://127.0.0.1:28080", "billing-api": "http://127.0.0.1:28081"} def call(aud, method, path, token, body=None): req = urllib.request.Request(BASE[aud] + path, method=method, data=json.dumps(body).encode() if body is not None else None, headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"}) try: with urllib.request.urlopen(req) as r: return r.status, json.loads(r.read()) except urllib.error.HTTPError as e: return e.code, json.loads(e.read()) def state(): with urllib.request.urlopen("http://127.0.0.1:28082") as r: return json.loads(r.read())