Skip to content

refactor: standardize API responses and add shared utilities - #174

Merged
javi11 merged 1 commit into
mainfrom
refactor/api-standardization-phase1-2
Dec 28, 2025
Merged

refactor: standardize API responses and add shared utilities#174
javi11 merged 1 commit into
mainfrom
refactor/api-standardization-phase1-2

Conversation

@javi11

@javi11 javi11 commented Dec 28, 2025

Copy link
Copy Markdown
Collaborator

Summary

  • Introduces Phase 1 shared utilities (errors package, HTTP client factory, config accessors, simplified DeepCopy)
  • Implements Phase 2 API standardization with unified response builders and handler migrations
  • Reduces code by ~1000 lines while improving consistency

Test plan

  • Run go build ./... - builds successfully
  • Run go test ./... - all tests pass
  • Manual testing of API endpoints for correct response format
  • Verify SABnzbd API compatibility with external clients

🤖 Generated with Claude Code

This is a comprehensive refactoring that introduces:

## Phase 1: Shared Utilities
- Add shared errors package (`internal/errors`) with NonRetryableError
- Add HTTP client factory (`internal/httpclient`) with preset timeouts
- Add config accessor methods (`internal/config/accessors.go`)
- Simplify DeepCopy using jinzhu/copier (235 lines → 15 lines)

## Phase 2: API Standardization
- Create unified response builders (`internal/api/response.go`)
- Migrate all handlers to use response builders:
  - queue_handlers.go
  - health_handlers.go
  - config_handlers.go
  - auth_handlers.go
- Apply admin middleware to protected routes
- SABnzbd handlers intentionally unchanged (API compatibility)

## Benefits
- Consistent JSON response format across all endpoints
- DRY error handling with standard error codes
- Reduced code duplication
- Centralized HTTP client configuration
- Improved maintainability

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@javi11
javi11 merged commit 8700e63 into main Dec 28, 2025
1 check passed
@javi11
javi11 deleted the refactor/api-standardization-phase1-2 branch February 4, 2026 13:41
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.

1 participant