Skip to content

docs(examples): revamp things-advanced to use media handling#2676

Closed
mmustafasenoglu wants to merge 1 commit into
falconry:masterfrom
mmustafasenoglu:docs/revamp-things-advanced-examples
Closed

docs(examples): revamp things-advanced to use media handling#2676
mmustafasenoglu wants to merge 1 commit into
falconry:masterfrom
mmustafasenoglu:docs/revamp-things-advanced-examples

Conversation

@mmustafasenoglu

Copy link
Copy Markdown

Summary

This PR revamps the things_advanced examples 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):

  • Removed JSONTranslator middleware - replaced with direct usage of req.get_media() and resp.media
  • Added TimingMiddleware - demonstrates req.context/resp.context usage by recording request processing time and setting Server-Timing header
  • Fixed on_get() - now uses resp.media = result instead of resp.context.result
  • Fixed on_post() - now uses req.get_media() instead of req.context.doc
  • Fixed debug comment - "API""App" ("Useful for debugging problems in your App")
  • Fixed ASGI Content-Length issue - removed the broken req.content_length == 0 check (moot with JSONTranslator removal)
  • Enabled AuthMiddleware in ASGI example (was commented out in README.rst but present in source file)

README.rst:

  • Synced embedded WSGI and ASGI code blocks with the updated example files
  • Fixed all discrepancies: import order, parameter order, AuthMiddleware status, string formatting

Rationale

Per the issue discussion with @vytas7 and @CaselIT:

  • JSONTranslator was removed altogether as it obscures Falcon's native media handling
  • TimingMiddleware was added as a lightweight replacement that still demonstrates middleware context patterns
  • The examples now properly showcase req.get_media() and resp.media as the recommended approach

Fixes #2309

- 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
@mmustafasenoglu mmustafasenoglu closed this by deleting the head repository Jul 12, 2026
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.

Revamp things-advanced (WSGI/ASGI) examples

1 participant