Skip to content

Conversation

@mcncl
Copy link
Contributor

@mcncl mcncl commented Feb 25, 2025

Description

This PR introduces a new internal/http package that provides a common HTTP client for making API requests. The implementation standardizes the way we set up authorization headers, handle errors, and process responses across the codebase.

Motivation

Previously, HTTP request setup with authorization appeared in multiple places:

  1. In pkg/cmd/api/api.go (apiCaller function)
  2. In internal/config/token.go (fetchTokenInfo method)

Both set up similar HTTP clients, handle authorization, and process responses, but with slightly different approaches. This led to code duplication and potential inconsistencies in error handling. By extracting this common logic into a single package, we can reduce duplication and ensure consistent behavior across the codebase.

Changes

  • Created new internal/http package with:
    • A client that handles common API operations (GET, POST, PUT, DELETE)
    • Standardized authorization header handling
    • Consistent error handling with detailed error messages
    • Support for configurable base URL and user agent
    • Comprehensive test suite
  • Refactored pkg/cmd/api/api.go to use the new HTTP client
  • Refactored internal/config/token.go to use the new HTTP client
  • Added documentation for the new package

Testing

The changes are covered by new unit tests in the internal/http package.

@mcncl mcncl enabled auto-merge (squash) February 25, 2025 01:45
@mcncl mcncl merged commit 6159611 into main Feb 26, 2025
1 check passed
@mcncl mcncl deleted the SUP-3443/http_client_improvements branch February 26, 2025 01:00
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.

3 participants