Type hinting could be another approach, where the framework would attempt to convert to the type specified for the on_*() parameters. This could perhaps be done in addition to supporting filters for more complex conversions.
You could implement this in (at least) a few different ways without modifying the framework directly. Any of these could be published as a standalone package to PyPI as a Falcon add-on:
- With a decorator on the resource class that introspects and wraps each on_*() responder method with code. This is probably the most performant strategy, since you only introspect the type hints once up front.
- With a process_resource() middleware method. Would require introspecting the type hints for every call.
- By overriding API._get_responder(). Call super and then transform the results before returning to the caller.
- By subclassing the default router and overriding the find() method. You could also override add_route() to construct a conversion lookup table and attach it to the new node, so that find() doesn't have to introspect the type hints each time.
Otherwise, if you like, you are more than welcome to file an issue to have this added to the framework directly. We would need a volunteer from the community to take on the work.
@kgriffs