Skip to content

docs: fix inaccurate examples and add architecture diagrams#6

Merged
christiangda merged 1 commit into
mainfrom
docs/improve-readme-diagrams
Jul 11, 2026
Merged

docs: fix inaccurate examples and add architecture diagrams#6
christiangda merged 1 commit into
mainfrom
docs/improve-readme-diagrams

Conversation

@christiangda

Copy link
Copy Markdown
Contributor

Summary

While reviewing the public documentation I found that many code snippets in the README and package doc (docs.go) did not compile or referenced APIs that don't exist. This PR corrects everything against the actual public API and adds Mermaid diagrams so users can understand the design at a glance.

No source behavior changes — docs only. go build, go vet, gofmt -l, and go test ./... (89%+ coverage) all pass.

What was wrong (and is now fixed)

Verified against the real exported API:

Docs said Reality
builder.HTTPMethod("") method is WithMethod
.Context(ctx), .QueryParams(...), .Headers(...), .RawBody(...), .BytesBody(...) WithContext, WithQueryParams, WithHeaders, WithRawBody, WithBytesBody
.Path(...), .Header(...), .BearerAuth(...), .JSONBody(...), .ContentType(...) (bare, in docs.go) all prefixed With…
client.GetBaseURL(), client.GetDefaultHeaders() do not exist — removed
"Base URL resolution for relative paths", "Default headers applied to all requests" not implemented — removed; Get/Post/… take a full URL
WithWithMethodGET() typos, stray httpx.) / httpx.// fragments removed / corrected
client.Get("/users/1") (relative) full URLs, matching the compiling example tests

Also documented options that existed but were missing from the docs: WithProxy, WithLogger, WithRetryStrategyAsString, and the whole NewHTTPRetryClient family (WithMaxRetriesRetry, WithRetryStrategyRetry, WithBaseTransport, WithProxyRetry, WithLoggerRetry).

Diagrams added (Mermaid, render natively on GitHub)

  1. Component overview — how RequestBuilder, GenericClient[T], ClientBuilder, and the retry transport compose over net/http
  2. Request lifecycle — sequence diagram including a 503 → retry → 200
  3. Composition model — which layers are optional / swappable (incl. injecting a mock HTTPClient)
  4. Error accumulation — how the builder collects and reports validation errors
  5. Retry decision flow — exactly what is and isn't retried
  6. Backoff comparison — delay-per-attempt chart for exponential / fixed / jitter

Other improvements

  • Corrected the CRUD example (used unsupported relative paths)
  • Added a table linking each example_*_test.go to what it demonstrates
  • Added a mocking/testing example using the HTTPClient interface
  • Clarified thread-safety (RequestBuilder is not concurrency-safe; clients are)
  • Completed the default-values table (added MaxIdleConnsPerHost, ExpectContinueTimeout)

Test plan

  • go build ./...
  • go vet ./...
  • gofmt -l clean
  • go test ./... passes (coverage 89.3%)
  • Verified every documented method/option against the exported API

🤖 Generated with Claude Code

The README and package documentation contained code snippets that did not
compile or referenced APIs that do not exist. This corrects them against the
actual public API and adds Mermaid diagrams to explain the design.

README.md:
- Fix broken snippets (stray `httpx.)` fragments, `WithWithMethodGET` typos)
- Correct method names to the real API: WithMethod (not HTTPMethod),
  WithContext (not Context), WithQueryParams/WithHeaders/WithRawBody/
  WithBytesBody (not QueryParams/Headers/RawBody/BytesBody)
- Remove references to methods that do not exist (GetBaseURL,
  GetDefaultHeaders) and to features the client does not provide
  ("base URL resolution", "default headers applied to all requests")
- Use full URLs in GenericClient.Get examples (relative paths are not
  supported by the convenience methods)
- Document previously-undocumented options: WithProxy, WithLogger,
  WithRetryStrategyAsString, and the NewHTTPRetryClient family
- Add an mocking example leveraging the HTTPClient interface
- Add Mermaid diagrams: component overview, request lifecycle sequence,
  composition model, error-accumulation flow, retry decision flow, and a
  backoff-strategy comparison chart

docs.go (package doc):
- Same broken-snippet and method-name fixes as the README
- Use full URLs and `any` instead of `interface{}` per project style

No source-behavior changes; go build, go vet, gofmt, and go test all pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@christiangda christiangda self-assigned this Jul 11, 2026
@christiangda christiangda merged commit 156a533 into main Jul 11, 2026
2 checks passed
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