Skip to content

Example: Resilient HTTP RoundTripper for Rate-Limited APIs #47

@cinar

Description

@cinar

Description: API integrations frequently encounter 429 Too Many Requests. This example will demonstrate how to create a custom http.RoundTripper that automatically pauses and resumes based on server-dictated Retry-After headers.

  • Architecture & Implementation Requirements:

    • Setup: Create examples/http_ratelimit/main.go.
    • The Transport: Implement a custom struct ResilientTransport that wraps http.DefaultTransport.
    • Integration: Inside the RoundTrip method, wrap the downstream HTTP call in resile.Do.
    • Header Parsing: If the response is a 429, parse the Retry-After header (handling both integer seconds and HTTP date formats). Have the policy return a custom RateLimitError that implements Resile's RetryAfter() interface.
  • Acceptance Criteria:

    • Provide a local mock HTTP server within the example that intentionally returns 429 responses to demonstrate the backoff dynamically.
    • Document how to inject this RoundTripper seamlessly into an existing http.Client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions