docs(examples): revamp things-advanced to use media handling#2676
Closed
mmustafasenoglu wants to merge 1 commit into
Closed
docs(examples): revamp things-advanced to use media handling#2676mmustafasenoglu wants to merge 1 commit into
mmustafasenoglu wants to merge 1 commit into
Conversation
- Remove JSONTranslator middleware, use req.get_media() and resp.media - Replace with TimingMiddleware to demonstrate context usage - Fix 'API' -> 'App' in debug comment - Sync README.rst embedded code blocks with example files - Fix ASGI example: AuthMiddleware now enabled, consistent param order Fixes #2309
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.
Summary
This PR revamps the
things_advancedexamples to showcase Falcon's built-in media handling instead of manual JSON serialization, as requested in #2309.Changes
examples/things_advanced.py(WSGI) &examples/things_advanced_asgi.py(ASGI):JSONTranslatormiddleware - replaced with direct usage ofreq.get_media()andresp.mediaTimingMiddleware- demonstratesreq.context/resp.contextusage by recording request processing time and settingServer-Timingheaderon_get()- now usesresp.media = resultinstead ofresp.context.resulton_post()- now usesreq.get_media()instead ofreq.context.doc"API"→"App"("Useful for debugging problems in your App")req.content_length == 0check (moot withJSONTranslatorremoval)AuthMiddlewarein ASGI example (was commented out in README.rst but present in source file)README.rst:AuthMiddlewarestatus, string formattingRationale
Per the issue discussion with @vytas7 and @CaselIT:
JSONTranslatorwas removed altogether as it obscures Falcon's native media handlingTimingMiddlewarewas added as a lightweight replacement that still demonstrates middleware context patternsreq.get_media()andresp.mediaas the recommended approachFixes #2309