Coverage for src/fluree_py/http/mixin/request.py: 87%
15 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-02 03:03 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-02 03:03 +0000
1"""Base mixin for HTTP request handling in Fluree operations."""
3from abc import ABC, abstractmethod
4from dataclasses import dataclass
6from httpx import Request
8from fluree_py.http.protocol.mixin.request import SupportsRequestCreation
9from fluree_py.types.common import JsonObject
12@dataclass(frozen=True, kw_only=True)
13class RequestMixin(ABC, SupportsRequestCreation):
14 """Base class for creating and managing HTTP requests."""
16 def get_request(self) -> Request:
17 """Constructs an HTTP request with the operation's data.
19 Exceptions:
20 NotImplementedError: If get_url() or build_request_payload() are not implemented.
21 """
22 return Request(
23 method="POST",
24 url=self.get_url(),
25 json=self.build_request_payload(),
26 )
28 @abstractmethod
29 def get_url(self) -> str:
30 """Returns the endpoint URL for the request.
32 Exceptions:
33 NotImplementedError: If not implemented by subclass.
34 """
35 ...
37 @abstractmethod
38 def build_request_payload(self) -> JsonObject:
39 """Constructs the JSON payload for the request.
41 Exceptions:
42 NotImplementedError: If not implemented by subclass.
43 """
44 ...