From dd7f07b2d00c8883cd5175d20f56f318a3c394e8 Mon Sep 17 00:00:00 2001 From: Kirill Date: Mon, 24 Aug 2026 15:47:40 +0300 Subject: [PATCH] feat(models): Added Executor class Executor performs HTTP requests: - Uses httpx for HTTP calls - Resolves {{variable}} in URLs - Returns Response with status, body, headers --- models/executor.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 models/executor.py diff --git a/models/executor.py b/models/executor.py new file mode 100644 index 0000000..9a27e8e --- /dev/null +++ b/models/executor.py @@ -0,0 +1,35 @@ +import httpx +from .context import Context +from .itm import RequestModel + + +class Response: + def __init__(self, status: int, body: dict, headers: dict): + self.status = status + self.body = body + self.headers = headers + + +class Executor: + def __init__(self, context: Context): + self.context = context + + def execute(self, request: RequestModel) -> Response: + url = self.context.resolve(request.path) + if not url.startswith("http"): + url = f"{self.context.config.base_url}{url}" + + with httpx.Client() as client: + resp = client.request( + method=request.method, + url=url, + headers=request.headers, + json=request.body if request.body_type == "json" else None, + timeout=request.timeout, + ) + + return Response( + status=resp.status_code, + body=resp.json() if resp.headers.get("content-type", "").startswith("application/json") else {}, + headers=dict(resp.headers), + )