Skip to main content

Features

  • Simple, fluent API for making HTTP requests
  • Function options pattern for configuration
  • Context support for cancellation and timeouts
  • Middleware support for request customization
  • Generic response handling
  • Built-in middleware implementations for common use cases
  • Comprehensive test coverage

Basic Usage

Advanced Usage

Middleware

The client supports middleware for request customization:

Request-specific options

You can add headers or other options to specific requests:

POST requests with JSON body

Middleware Implementations

The package includes several built-in middleware implementations:
  • AuthBearerMiddleware: Adds a Bearer token to the Authorization header
  • BasicAuthMiddleware: Adds basic authentication to the request

Custom Middleware

You can create your own middleware:

Error Handling

The client returns comprehensive errors that can be unwrapped:

Inbuilt Tracing

When using tracing alongside an http client, you can enable tracing using
Which will create spans for your http calls. Note that in case of using retry, it will only create one span for the entire operation, and not per retry.

Response Helpers

The Response type provides helper methods:
  • Unmarshal(v interface{}): Decodes the response body into a struct
  • String(): Returns the response body as a string
  • IsSuccess(): Returns true if the status code is in the 2xx range