Skip to content

allow multiple route before functions#867

Merged
jph00 merged 1 commit intomainfrom
multi-before-func
Apr 27, 2026
Merged

allow multiple route before functions#867
jph00 merged 1 commit intomainfrom
multi-before-func

Conversation

@RensDimmendaal
Copy link
Copy Markdown
Contributor

@RensDimmendaal RensDimmendaal commented Apr 23, 2026

Proposed Changes
Allow multiple before functions in a route so you can do things like

@rt(before=(check_user, limit('20/d'))
def index(sess): ...

Types of changes
What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist
Go over all the following points, and put an x in all the boxes that apply:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I am aware that this is an nbdev project, and I have edited, cleaned, and synced the source notebooks instead of editing .py or .md files directly.

Additional Information
Any additional information, configuration or data that might be necessary to reproduce the issue.

@RensDimmendaal RensDimmendaal added the enhancement New feature or request label Apr 23, 2026
@RensDimmendaal RensDimmendaal requested a review from jph00 April 23, 2026 08:38
@RensDimmendaal RensDimmendaal mentioned this pull request Apr 23, 2026
9 tasks
Comment thread fasthtml/core.py
# %% ../nbs/api/00_core.ipynb #26b147ba
@patch
def _endp(self:FastHTML, f, body_wrap, before=None):
def _endp(self:FastHTML, f, body_wrap, before:Optional[Callable|tuple]=None):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of adding this complex typing tbh - not sure it's much of a win in dynamic environments, and adds clutter that (for me at least) makes it harder to see what's happening.

Comment thread fasthtml/core.py
# %% ../nbs/api/00_core.ipynb #f5cb2c2b
@patch
def route(self:FastHTML, path:str=None, methods=None, name=None, include_in_schema=True, body_wrap=None, host=None, before=None):
def route(self:FastHTML, path:str=None, methods=None, name=None, include_in_schema=True, body_wrap=None, host=None, before:Optional[Callable|tuple]=None):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...Ugh and it ends up cluttering every function it's threaded thru! :O

@jph00 jph00 merged commit 3fa209a into main Apr 27, 2026
2 checks passed
@jph00 jph00 deleted the multi-before-func branch April 27, 2026 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants