Skip to content

refactor: extract API transport layer into independent module - #416

Open
hanthor-hive-agent[bot] wants to merge 2 commits into
mainfrom
arch/api-adapter
Open

hanthor-hive-agent[bot] wants to merge 2 commits into
mainfrom
arch/api-adapter

Conversation

@hanthor-hive-agent

Copy link
Copy Markdown
Contributor

Refactor

Extracts HTTP communication logic from app.js into a dedicated apiClient.js module, centralizing all API transport and endpoint construction.

Changes

apiClient.js (Phase 1 extraction)

  • api() β€” core fetch wrapper with status checking and error handling
  • post(), patch(), deleteRequest() β€” HTTP method helpers
  • vmURL(), vmKey(), ctKey() β€” URL and key construction
  • listVMs(), listContexts(), getWhoami() β€” common API queries

app.js updates

  • Imports API functions from apiClient.js
  • Removes ~100 LOC of duplicate implementations
  • Retains local helper functions (findVM, findCT, etc.) that depend on imported utilities

Benefits

  1. Testability: API logic can be unit tested independently
  2. Reusability: Other dashboard components can import apiClient functions
  3. Maintainability: All HTTP communication in one place
  4. Phase 2 ready: Enables caching, batch requests, request deduplication without modifying app.js

Phase 2 Roadmap

  • Add request caching with TTL
  • Implement batch request support
  • Add request deduplication

Phase 3 Roadmap

  • Add WebSocket transport for real-time updates
  • Implement connection pooling and reconnection logic

Closes #406


Filed by architect agent (ACMM L6 β€” full mode)

β€” hive: agent=architect backend=pi model=kiro-api-key/claude-haiku-4-5:low pi=1.0.0

- Create apiClient.js module with centralized API functions:
  - api() β€” core fetch wrapper with error handling
  - post(), patch(), deleteRequest() β€” HTTP method helpers
  - vmURL(), vmKey(), ctKey() β€” URL and key construction
  - listVMs(), listContexts(), getWhoami() β€” common API queries

- Update app.js to:
  - Import API functions from apiClient.js
  - Remove duplicate inline implementations
  - Keep local helper functions (findVM, findCT, tagChips, etc.)

This Phase 1 extraction establishes a testable API boundary and enables
Phase 2 work (caching, batch requests) and Phase 3 (WebSocket transport)
without modifying the main app logic.

Closes #406

Signed-off-by: architect <architect@hive.kubestellar.io>
@hanthor-hive-agent
hanthor-hive-agent Bot requested a review from hanthor as a code owner October 5, 2026 03:28
@github-actions
github-actions Bot removed the request for review from hanthor October 5, 2026 03:28
The local post(vm, path, body) and patch(vm, path, body) functions have
different signatures than the apiClient versions. Remove the conflicting
imports to prevent shadowing and breaking the e2e/ui-smoke tests.

Keep importing core utilities: api, vmURL, vmKey, ctKey

Signed-off-by: architect <architect@hive.kubestellar.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[architect] corral: Phase 1 β€” extract API adapter module from app.js

0 participants