Repository navigation
feat: Let a resource and an endpoint set headers for their requests - #214
Merged
Merged
Conversation
- Add a headers= class argument to Resource and AsyncResource, and a headers= option to each verb decorator, checked like a client class's headers= when the class or decorator is defined. - Add them to each request when it's built: the most specific wins, name by name: the client's headers, then the resource's, then the endpoint's, then a Header() argument passed on the call. - Merge a resource subclass's headers over its parent's. A resource mounted on another doesn't get its headers, as for prefixes and tags. - Move the header check into _headers.py, shared by clients, resources and endpoints. - Show header names, not values, in client and resource reprs. - Name the class arguments in the ClientX, AsyncClientX and Resource docstrings, and say they must be passed by name. - Document resource and endpoint headers in the guide, the reference, llms.txt, CLAUDE.md and the changelog. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
slatecipher
force-pushed
the
feat/resource-and-method-headers
branch
from
December 4, 2026 16:44
996613f to
475a550
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
A client class can set headers sent on every request (#204), but a group of endpoints, or one endpoint, couldn't: an
Accept: text/csvfor one export endpoint had to be aHeader()parameter every caller passed. This adds headers at the resource and endpoint levels.ResourceandAsyncResourcetake aheaders=class argument, and each verb decorator aheaders=option, as in@method.get("/export", headers={"Accept": "text/csv"}). They're checked like a client class'sheaders=when the class or decorator is defined.Header()argument passed on the call._headers.py, shared by clients, resources and endpoints.ClientX,AsyncClientXandResourcedocstrings, which say they must be passed by name.docs/resources.mdwith a new sample,configuration.md,requests.md), the reference,llms.txt,CLAUDE.mdand the changelog (### Added).Closes #209
Testing
make checkpasses: lint, type checks, and 394 tests with the coverage gate.test_clients.pyandtest_query_and_headers.pycover the order headers win in, resource subclass merging, mounted resources not getting their parent's headers, and the definition-time checks.test/test_docs.pyruns the newdocs_src/resources/headers.pysample.🤖 Generated with Claude Code