mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 11:56:18 -05:00
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
|
|
"""HTTP client for the WROLPi API."""
|
||
|
|
import httpx
|
||
|
|
|
||
|
|
from wrolpi_mcp.config import API_BASE_URL, VERIFY_TLS
|
||
|
|
|
||
|
|
|
||
|
|
async def api_get(path: str, params: dict | None = None) -> dict:
|
||
|
|
"""GET request to the WROLPi API. Returns parsed JSON."""
|
||
|
|
async with httpx.AsyncClient(base_url=API_BASE_URL, verify=VERIFY_TLS, timeout=30.0) as client:
|
||
|
|
resp = await client.get(path, params=params)
|
||
|
|
resp.raise_for_status()
|
||
|
|
return resp.json()
|
||
|
|
|
||
|
|
|
||
|
|
async def api_post(path: str, json: dict | None = None) -> dict:
|
||
|
|
"""POST request to the WROLPi API. Returns parsed JSON."""
|
||
|
|
async with httpx.AsyncClient(base_url=API_BASE_URL, verify=VERIFY_TLS, timeout=30.0) as client:
|
||
|
|
resp = await client.post(path, json=json or {})
|
||
|
|
resp.raise_for_status()
|
||
|
|
return resp.json()
|
||
|
|
|
||
|
|
|
||
|
|
async def api_get_text(path: str) -> str:
|
||
|
|
"""GET request that returns raw text/HTML."""
|
||
|
|
async with httpx.AsyncClient(base_url=API_BASE_URL, verify=VERIFY_TLS, timeout=30.0) as client:
|
||
|
|
resp = await client.get(path)
|
||
|
|
resp.raise_for_status()
|
||
|
|
return resp.text
|