(self, routes: Dict[str, ApiHandler], body: Dict[str, Any] | None = None)
| 513 | self.end_headers() |
| 514 | self.wfile.write(data) |
| 515 | |
| 516 | def _handle_api(self, routes: Dict[str, ApiHandler], body: Dict[str, Any] | None = None) -> None: |
| 517 | path, query_params = _query(self.path) |
| 518 | route = routes.get(path) |
| 519 | if route is None: |
| 520 | self._send_json({"ok": False, "error": f"Unknown API route: {path}"}, status=HTTPStatus.NOT_FOUND) |
| 521 | return |
| 522 | try: |
| 523 | payload = route(query_params, body or {}) |
| 524 | self._send_json({"ok": True, **payload}) |
| 525 | except Exception as exc: |
| 526 | self._send_json({"ok": False, "error": str(exc)}, status=HTTPStatus.BAD_REQUEST) |
| 527 | |
| 528 | def _send_sse_event(self, event: str, payload: Dict[str, Any]) -> None: |
no test coverage detected