Skip to content

Refactor recognize to take params as kwarg#301

Open
cllns wants to merge 1 commit intomainfrom
fix-recognize
Open

Refactor recognize to take params as kwarg#301
cllns wants to merge 1 commit intomainfrom
fix-recognize

Conversation

@cllns
Copy link
Copy Markdown
Member

@cllns cllns commented Apr 16, 2026

Fixes #271.

Router#recognize was silently ignoring the method: kwarg when called without an explicit params hash, returning the verb as GET for POST routes and often picking the wrong route.

Root cause: the old signature recognize(env, params = {}, options = {}) absorbed method: :post into the positional params argument, leaving options empty when it was handed to Rack::MockRequest.env_for.

Fixes the bug by moving to an explicit kwargs signature:

# Before
def recognize(env, params = {}, options = {})

# After
def recognize(target, params: {}, **options)

I also renamed env to target to reflect that the argument accepts a path, a route name, or a Rack env hash.

This is a breaking change, so will need to be for hanami-router v3. It seems like a good time to fix this "the right way" instead of making a backward-compatible fix that we'd have to continue to maintain. This new approach is much more explicit.

There's a slight behavior change in that we double splat the keyword args, so they're converted to symbols, so e.g. "HTTP_AUTHORIZATION" will get converted to a symbol, which Rack drops. There's a very simple fix though: callers who need this can build the env explicitly via Rack::MockRequest.env_for and pass it in as the target.

I worked with Claude Code to get this fixed, refactored, and all of the documentation updated.

Fixes #271. This is a breaking change
@cllns cllns changed the title Refactor recognize to take params as kwarg Refactor recognize to take params as kwarg Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Router.recognize sets GET to the verb of POST routes

1 participant