Skip to content

docs(decoders): add a "write your own ResponseDecoder" guide#67

Merged
lesnik512 merged 2 commits into
mainfrom
docs/custom-decoder-guide
Jun 16, 2026
Merged

docs(decoders): add a "write your own ResponseDecoder" guide#67
lesnik512 merged 2 commits into
mainfrom
docs/custom-decoder-guide

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

Adds docs/decoders.md, the Seam B extension-point guide — the decoder counterpart to docs/middleware.md. Closes deferred item G6 (custom-ResponseDecoder guide).

Contents

The page mirrors the structure of the middleware guide:

  • The protocolcan_decode / decode, the can_decode no-raise obligation (it runs outside the DecodeError wrap), and auto-DecodeError wrapping of decode failures.
  • How the client resolves a modeldecoders=[...] order as preference, the pydantic-first None default, and the MissingDecoderError pre-flight vs DecodeError distinction.
  • Decoders are sync — for both clients — one protocol shared by Client and AsyncClient, unlike middleware's two flavors.
  • Worked example: a CSV decodertext/csvlist[<dataclass>], stdlib-only and single-pass, chosen because both built-ins are JSON so it best teaches that the seam is raw-bytes-in / typed-object-out.
  • Claiming the right models — the discrimination obligation, a cattrs/attrs adapter sketch, and that the single-pass rule is a built-in perf choice, not a hard obligation.
  • When NOT to write a decoder.

Also

  • mkdocs.ymlDecoders nav entry after Middleware.
  • planning/deferred.md — G6 removed (closed).
  • Planning bundle 2026-06-15.01-custom-decoder-guide.

No source or public-API change.

Verification

  • CSV example exercised against the real ResponseDecoder protocol — can_decode accepts list[Sale] and rejects list / list[int] / Sale / dict; decode round-trips a CSV body.
  • mkdocs build --strict — clean (links resolve, nav builds).
  • just lint — clean.

🤖 Generated with Claude Code

lesnik512 and others added 2 commits June 16, 2026 08:34
Add docs/decoders.md, the Seam B extension-point guide that mirrors
docs/middleware.md: the can_decode/decode protocol (no-raise obligation,
auto-DecodeError wrapping), decoders=[...] list-order resolution and the
MissingDecoderError pre-flight, a sync-for-both-clients callout, a runnable
CSV worked example, and the "claim narrowly / two-pass is allowed" note.

Closes deferred item G6 (custom-decoder guide) and wires the page into the
mkdocs nav after Middleware. No source or public-API change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Ship bookkeeping for PR #67: mark the change shipped (pr: 67, outcome filled),
move the bundle from changes/active/ to changes/archive/, and flip its Index
line from Active to Archived.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit b7cc53b into main Jun 16, 2026
5 checks passed
@lesnik512 lesnik512 deleted the docs/custom-decoder-guide branch June 16, 2026 05:46
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