MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / async_request

Method async_request

agentops/client/http/http_client.py:112–169  ·  view source on GitHub ↗

Make an async HTTP request and return JSON response Args: method: HTTP method (e.g., 'get', 'post', 'put', 'delete') url: Full URL for the request data: Request payload (for POST, PUT methods) headers: Request headers time

(
        cls,
        method: str,
        url: str,
        data: Optional[Dict] = None,
        headers: Optional[Dict] = None,
        timeout: int = 30,
    )

Source from the content-addressed store, hash-verified

110
111 @classmethod
112 async def async_request(
113 cls,
114 method: str,
115 url: str,
116 data: Optional[Dict] = None,
117 headers: Optional[Dict] = None,
118 timeout: int = 30,
119 ) -> Optional[Dict]:
120 """
121 Make an async HTTP request and return JSON response
122
123 Args:
124 method: HTTP method (e.g., 'get', 'post', 'put', 'delete')
125 url: Full URL for the request
126 data: Request payload (for POST, PUT methods)
127 headers: Request headers
128 timeout: Request timeout in seconds
129
130 Returns:
131 JSON response as dictionary, or None if request failed
132 """
133 if not AIOHTTP_AVAILABLE:
134 logger.warning("aiohttp not available, cannot make async request")
135 return None
136
137 try:
138 session = await cls.get_async_session()
139 if not session:
140 return None
141
142 logger.debug(f"Making async {method} request to {url}")
143
144 # Prepare request parameters
145 kwargs = {"timeout": aiohttp.ClientTimeout(total=timeout), "headers": headers or {}}
146
147 if data and method.lower() in ["post", "put", "patch"]:
148 kwargs["json"] = data
149
150 # Make the request
151 async with session.request(method.upper(), url, **kwargs) as response:
152 logger.debug(f"Async request response status: {response.status}")
153
154 # Check if response is successful
155 if response.status >= 400:
156 return None
157
158 # Parse JSON response
159 try:
160 response_data = await response.json()
161 logger.debug(
162 f"Async request successful, response keys: {list(response_data.keys()) if response_data else 'None'}"
163 )
164 return response_data
165 except Exception:
166 return None
167
168 except Exception:
169 return None

Callers

nothing calls this directly

Calls 2

get_async_sessionMethod · 0.80
jsonMethod · 0.80

Tested by

no test coverage detected