WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Feature Request: Official minimal BaseHandler class for clean, decorator-free route handlers #4522

@see7788

Description

@see7788

What is the feature you are proposing?

Hi Hono team!

I love that Hono is fast, tiny, and avoids unnecessary abstractions. But when building apps, I keep coming back to a simple need: a built-in way to write plain class-based handlers without decorators, middleware chains, or reflection.

The core idea is this: a service is just a few classes (for GET, POST, WS, etc.), each with:

Special members like headers, cookie, query, body
Public methods like json(), jsx(), redirect(), validate(), jwt.sign()
No @get(), no DI containers, no pipeline — just explicit, testable, readable code.

Example:

ts
编辑
class LoginHandler extends BaseHandler {
async handle() {
const { email, password } = await this.body;
if (!this.cookie.includes('auth=')) {
return this.json({ error: 'Unauthorized' }, 401);
}
const user = await db.find(email);
return this.json({ id: user.id, name: user.name });
}
}

app.post('/login', (c) => new LoginHandler(c).handle());
This pattern is:

Easy to test (just new LoginHandler(mockCtx))
Fully tree-shakable
Zero runtime overhead
Aligns with Hono’s “you don’t pay for what you don’t use” philosophy
Proposal:

Export a lightweight BaseHandler class from hono (or hono/handler)
Pre-bind common properties (this.body, this.cookie, etc.) and helpers (this.json())
Document this as an official “minimal class-based” style
It wouldn’t change anything for existing users — just give simplicity-minded developers a blessed path.

Would you consider this? I’d be happy to help draft a PR.

Thanks for your amazing work! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions