35 lines
891 B
Python
35 lines
891 B
Python
import urequests # type: ignore
|
|
import json
|
|
|
|
BASE_API_URL: str = "http://api-server:8000"
|
|
|
|
|
|
class API_Server_Checker:
|
|
def __init__(self):
|
|
pass
|
|
|
|
def _get_items(self, item_id: int = 0):
|
|
items_url: str = (
|
|
f"{BASE_API_URL}/items"
|
|
if item_id == 0
|
|
else f"{BASE_API_URL}/items/{item_id}"
|
|
)
|
|
print(f"query: {items_url}")
|
|
|
|
try:
|
|
r = urequests.get(items_url)
|
|
print("Status-Code:", r.status_code)
|
|
json_resp = r.json()
|
|
|
|
if r.status_code == 200:
|
|
print("json_resp:", json_resp)
|
|
else:
|
|
print("api-server error:", json_resp["error"]["message"])
|
|
except OSError as e:
|
|
print(f"api-server call failed: {e}")
|
|
finally:
|
|
r.close()
|
|
|
|
def check(self, item_id: int):
|
|
self._get_items(item_id)
|