Skip to content

feat(routing): support helper middleware#161

Merged
imdhemy merged 1 commit into
2.xfrom
dmi/allow-middleware-http-verb-helpers
Apr 28, 2026
Merged

feat(routing): support helper middleware#161
imdhemy merged 1 commit into
2.xfrom
dmi/allow-middleware-http-verb-helpers

Conversation

@imdhemy

@imdhemy imdhemy commented Apr 28, 2026

Copy link
Copy Markdown
Member
Q A
License GPLv3
Issue Closes #159

Summary

Adds middleware support to function-first HTTP verb helpers.

HTTP helpers now accept zero or more middleware functions before the final handler, for both named and unnamed routes:

  • Get('/users', authMiddleware, handler)
  • Get('/users', 'users.list', authMiddleware, handler)

The final function argument is treated as the handler. Any preceding functions after the optional route name are treated as route middleware and run before the handler in declaration order.

- allow verb helpers to accept middleware before handlers
- preserve named and unnamed helper behavior

Copilot AI left a comment

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.

Pull request overview

Adds middleware support to the function-first HTTP verb helpers (e.g., Get, Post) so callers can supply zero or more middleware functions before the final handler, with optional route naming preserved.

Changes:

  • Extends HTTP verb helper signatures to accept (...middleware, handler) with optional (name, ...middleware, handler).
  • Updates verb helper argument parsing to extract middleware[] and handler, and throws clearer runtime errors when no handler is provided.
  • Adds/updates unit + E2E tests to validate middleware ordering and named/unnamed helper behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/function-first-routing.e2e.test.ts Adds an E2E assertion that verb-helper-declared middleware runs in declaration order; updates a grouped route config test to use Post helper.
src/routing/helpers/http-verb-helpers.ts Implements middleware+handler parsing for verb helpers and wires extracted middleware into Route(...).
src/routing/helpers/http-verb-helpers.test.ts Adds unit tests for middleware extraction and for throwing when handlers are missing.

@imdhemy imdhemy merged commit 7b2dfa4 into 2.x Apr 28, 2026
5 checks passed
@imdhemy imdhemy deleted the dmi/allow-middleware-http-verb-helpers branch April 28, 2026 20:52
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.

feat(routing): allow middleware in HTTP verb helpers

2 participants