HTTPower.Profiles (HTTPower v0.16.0)

View Source

Pre-configured profiles for common HTTPower use cases.

Profiles encode best practices for middleware coordination, providing optimal settings for different scenarios out of the box.

Available Profiles

  • :payment_processing - Conservative settings for payment gateways and financial APIs
  • :high_volume_api - High-throughput settings for APIs that handle large request volumes
  • :microservices_mesh - Optimized for microservices inter-service communication

Usage

# Use a profile when creating a client
client = HTTPower.new(
  base_url: "https://payment-gateway.com",
  profile: :payment_processing
)

# Profile settings are merged with explicit options (explicit wins)
client = HTTPower.new(
  base_url: "https://api.example.com",
  profile: :high_volume_api,
  rate_limit: [requests: 2000]  # Override profile's rate limit
)

Profile Details

:payment_processing

Optimized for payment gateways (Stripe, PayPal, etc.) where reliability and correctness are more important than speed.

  • Rate limiting: Conservative (100 req/min), adaptive based on circuit health
  • Circuit breaker: Aggressive (30% failure threshold), long timeout for slow payment APIs
  • Deduplication: Enabled with 5s window to prevent double charges
  • Retry: 3 attempts with longer delays (payment APIs are slow)

Key benefit: Prevents double charges and duplicate orders automatically.

:high_volume_api

Optimized for public APIs or internal services that need to handle high request volumes efficiently.

  • Rate limiting: High throughput (1000 req/min), adaptive
  • Circuit breaker: More tolerant (50% failure threshold), fast recovery
  • Deduplication: Short window (1s), response sharing across concurrent requests
  • Retry: Fewer attempts (2x) with fast delays

Key benefit: Maximum throughput with dedup providing 5x capacity boost.

:microservices_mesh

Optimized for microservices calling each other in a service mesh.

  • Rate limiting: Moderate (500 req/min), adaptive
  • Circuit breaker: Balanced (40% threshold), signals rate limiter
  • Deduplication: Critical for retry storms, 2s window
  • Retry: Standard retries with moderate delays

Key benefit: Prevents cascade failures and retry storms between services.

Summary

Functions

Gets a profile by name.

Returns configuration for high-volume API use cases.

Lists all available profile names.

Returns configuration for microservices mesh use cases.

Returns configuration for payment processing use cases.

Functions

get(arg1)

@spec get(atom()) :: {:ok, keyword()} | {:error, :unknown_profile}

Gets a profile by name.

Returns {:ok, config} for valid profiles, {:error, :unknown_profile} otherwise.

Examples

iex> HTTPower.Profiles.get(:payment_processing)
{:ok, [rate_limit: [...], circuit_breaker: [...], ...]}

iex> HTTPower.Profiles.get(:invalid)
{:error, :unknown_profile}

high_volume_api()

@spec high_volume_api() :: keyword()

Returns configuration for high-volume API use cases.

Best for: Public APIs, high-traffic internal services, content APIs. Priority: Throughput > Latency

list()

@spec list() :: [atom()]

Lists all available profile names.

Examples

iex> HTTPower.Profiles.list()
[:payment_processing, :high_volume_api, :microservices_mesh]

microservices_mesh()

@spec microservices_mesh() :: keyword()

Returns configuration for microservices mesh use cases.

Best for: Service-to-service calls, internal microservices, Kubernetes. Priority: Reliability > Individual Request Speed

payment_processing()

@spec payment_processing() :: keyword()

Returns configuration for payment processing use cases.

Best for: Stripe, PayPal, payment gateways, financial APIs. Priority: Correctness > Speed