Add json_or_text and save_to_file methods to Response class#12
Open
AndreyLebedev345 wants to merge 2 commits into
Open
Add json_or_text and save_to_file methods to Response class#12AndreyLebedev345 wants to merge 2 commits into
AndreyLebedev345 wants to merge 2 commits into
Conversation
This commit adds two new convenience methods to the Response class: 1. json_or_text(): Attempts to parse the response as JSON, automatically falling back to text content if JSON parsing fails. This provides a convenient way to handle responses that may be in either format without explicit exception handling. 2. save_to_file(path, mode='auto'): Saves response content to a file with intelligent handling of different content types. Supports multiple modes: - 'auto': Automatically detects format based on Content-Type header - 'binary': Saves raw bytes (images, PDFs, etc.) - 'text': Saves as text with encoding support - 'json': Parses and saves formatted JSON with indentation These methods enhance the Response API by providing commonly needed functionality that previously required manual implementation. The save_to_file method is particularly useful for downloading and storing various types of content from web APIs and servers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Auto-generated documentation update for PR #12 Docs-Updated-By: docs-bot
Owner
Author
📚 Documentation UpdatesAuto-committed:
🤖 Docs Bot |
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.
This commit adds two new convenience methods to the Response class:
json_or_text(): Attempts to parse the response as JSON, automatically falling back to text content if JSON parsing fails. This provides a convenient way to handle responses that may be in either format without explicit exception handling.
save_to_file(path, mode='auto'): Saves response content to a file with intelligent handling of different content types. Supports multiple modes:
These methods enhance the Response API by providing commonly needed functionality that previously required manual implementation. The save_to_file method is particularly useful for downloading and storing various types of content from web APIs and servers.
🤖 Generated with Claude Code
Summary
Checklist