Skip to content

Releases: honojs/hono

v2.2.1

21 Sep 14:11
Compare
Choose a tag to compare

This release includes the bug fix for running it on Bun.

What's Changed

  • fix: don't use defaultNotFoundMessage variable by @yusukebe in #549

Full Changelog: v2.2.0...v2.2.1

v2.2.0

21 Sep 04:34
Compare
Choose a tag to compare

This release includes ES Module support, innovative new features, and some bug fixes. You will like it.

Summary

Support ES Module

We have distributed only CommonJS, but now we will distribute ES Module. ES Module is used when the library is imported using the import keyword. ESModule may improve performance and reduces bundle size.

StaticRouter and SmartRouter

Now we have a really smart router.

Added a simple router named "StaticRouter" that does not support dynamic routes. Now, we have there router: "TrieRouter", "RegExpRouter", and "StaticRouter".

And we introduce "SmartRouter".

SmartRouter picks the optimal router from three routers the first time it is accessed. Users can use the fastest router without explicitly specifying a router.

// Before this release.
// If we wanted to use optimal router, we have to specify it.
const app = new Hono({ router: new RegExpRouter() })
// This release.
// SmartRouter selects the fastest router automatically.
const app = new Hono()

StaticRouter is used for having only static routes. Otherwise, RegExpRouter will be used, but it has routing that RegExpRouter does not support, TrieRouter will be used.

Validator Middleware

New Validator Middleware as builtin middleware. This validator is magic.

app.post(
  '/posts',
  validator((v) => ({
    post: {
      id: v.json('post.id').asNumber().isRequired(),
      title: v.json('post.title').isRequired().isLength({ max: 100 }),
      published: v.json('post.published').asBoolean(),
      body: v.json('post.body').isOptional(),
    },
  })),
  (c) => {
    const res = c.req.valid()
    const post = res.post
    return c.text(`Post: ${post.id} is ${post.title}`)
  }
)

They will have "Types"! The value validated with asNumber() keyword will have "Type".

ss02

Not only that.

  • Easy to understand the result data because "declaring property name first".
  • Easy to writing rules. v.isLength(400) is better than v.isLength, 400.
  • Getting only "declared properties". Additional properties are always ignored. It's safe.

For more information: https://honojs.dev/docs/builtin-middleware/validator/

Validator Middleware was provided as third party Middleware: https://github.com/honojs/validator, it will be deprecated.


All changes are below:

What's Changed

  • fix(types): correct types for app.notFound / app.onError by @yusukebe in #512
  • fix(middleware): support multiple middleware on bearer/basic auth middleware by @yusukebe in #513
  • Introduce StaticRouter and SmartRouter by @usualoma in #501
  • feat(middleware): introduce "built-in" Validator Middleware by @yusukebe in #505
  • Lightweight RegExpRouter reborn by @usualoma in #519
  • fix(types): add types to middleware correctly by @yusukebe in #521
  • feat(validator): add isFalsy and isNotFalsy by @yusukebe in #523
  • docs(readme): update discord invite url by @OnurGvnc in #527
  • feat: support ES modules!! by @yusukebe in #526
  • feat(validator): add isBoolean and isNumber by @yusukebe in #530
  • feat(cors): allow multiple origins by @yusukebe in #531
  • Check in Origin header instead of Referer by @usualoma in #532
  • feat(cors): Enable to check origin header by a function. by @usualoma in #533
  • fix(deno): serve static middleware returns 404 correctly by @yusukebe in #537
  • fix(bun): serve static middleware returns 404 correctly by @yusukebe in #538
  • feat: another idea of Validator Middleware by @yusukebe in #535
  • fix(redirect): don't have to make relative url to absolute one by @yusukebe in #541
  • feat: support appending values with c.header by @yusukebe in #539
  • feat: c.req.body and c.req.json accept generics by @yusukebe in #529
  • fix(validator): make "Types" work well by @yusukebe in #545
  • feat(validator): Enable verification results to be retrieved as structured data. by @usualoma in #547

New Contributors

Full Changelog: v2.1.4...v2.2.0

v2.1.4

05 Sep 13:03
Compare
Choose a tag to compare

Summary

Performance tuning!

This release includes performance improvement. "Hello World" will be 11% faster and c.req.query 25% faster on Bun. Of course, it becomes faster on Deno.

What's Changed

  • perf: do not compose if it has only one handler by @yusukebe in #493
  • fix: fixed the issue logger called twice by @yusukebe in #494
  • perf(compose): Remove await composed() from hono.ts. by @usualoma in #495
  • perf(compose): Always return a Promise without async. by @usualoma in #496
  • perf(req): improve c.req.query performance by @yusukebe in #498
  • Fix regexp ambigous route by @usualoma in #499

Full Changelog: v2.1.3...v2.1.4

v2.1.3

31 Aug 09:06
Compare
Choose a tag to compare

Summary

This is a patch release including minor bug fixes.

What's Changed

New Contributors

Full Changelog: v2.1.2...v2.1.3

v2.1.2

28 Aug 09:26
Compare
Choose a tag to compare

Summary

This is also a patch release.

What's Changed

Full Changelog: v2.1.1...v2.1.2

v2.1.1

27 Aug 15:00
Compare
Choose a tag to compare

Summary

This is a patch release. Fixed type errors.

What's Changed

  • fix(type): fix type errors for Bindings and Variables by @yusukebe in #488

Full Changelog: v2.1.0...v2.1.1

v2.1.0

27 Aug 06:55
Compare
Choose a tag to compare

BREAKING CHANGES

This release has the breaking changes. Please see the migration guide for more detail:

Summary

  • TrieRouter is 9~10% faster.
  • Enable adding types to c.set/c.get by passing the Generics to new Hono. #472
  • c.req.parseBody parses only FormData. Does not parse JSON, text, or ArrayBuffer. #487

Types for c.set/c.get

Now, we can add the types to the variables used in c.set and c.get. new Hono receive the Generics for the variables and bindings which is for environment variables for Cloudflare Workers.

type Bindings = {
  KV: KVNamespace
  Storage: R2Bucket
}

type WebClient = {
  user: string
  pass: string
}

type Variables = {
  client: WebClient
}

const app = new Hono<{ Variables: Variables; Bindings: Bindings }>()

app.get('/foo', (c) => {
  const client = c.get('client') // client is WebClient
  const kv = c.env.KV // kv is KVNamespace
  //...
})

c.req.parseBody

Now, c.req.parseBody has become only for parsing FormData. We have to parse the request body explicitly.

// `multipart/form` or `application/x-www-form-urlencoded`
const data = await c.req.parseBody()

const jsonData = await c.req.json() // for JSON body
const text = await c.req.text() // for text body
const arrayBuffer = await c.req.arrayBuffer() // for ArrayBuffer

What's Changed

  • perf(trie-router): fine tuning, 9~10% faster by @yusukebe in #473
  • fix(context): export ContextVariableMap correctly by @yusukebe in #476
  • feat(types): enable adding Types for variables used in c.set/c.get by @yusukebe in #478
  • fix: enable passing Generics to c.req.parseBody, default is any by @yusukebe in #481
  • docs(readme): add discord and twitter links by @yusukebe in #485
  • [BREAKING] fix: make that c.req.parseBody parses only FormData by @yusukebe in #487

Full Changelog: v2.0.9...v2.1.0

v2.0.9

18 Aug 22:42
Compare
Choose a tag to compare

Summary

Performance improvement - We have revised the await/async process so that it is faster in some situations.

It has been 8-9% faster in the benchmark:

hono - trie-router(default) x 393,919 ops/sec ±4.52% (86 runs sampled)
hono - regexp-router x 478,140 ops/sec ±2.85% (83 runs sampled)
hono optimized - trie-router(default) x 427,940 ops/sec ±4.32% (81 runs sampled)
hono optimized - regexp-router x 512,488 ops/sec ±5.28% (75 runs sampled)
Fastest is hono optimized - regexp-router
✨  Done in 28.36s.

On Bun, it has been 15% faster.

Before: Requests/sec: 57043.0018
After:  Requests/sec: 65658.9860

What's Changed

  • fix(context): fixed ContextVariableMap is not enabled in built code by @yusukebe in #465
  • perf(compose): optimize await by @yusukebe in #466
  • docs(readme): update benchmark results by @yusukebe in #467
  • chore: add FUNDING.yml by @yusukebe in #468
  • fix(compose): Support a handler that non-async and returning a promise. by @usualoma in #469

Full Changelog: v2.0.8...v2.0.9

v2.0.8

10 Aug 12:56
Compare
Choose a tag to compare

Summary

Mostly bug fixes:

  • Fixed errors for ETag Middleware. There was a bug returning a server error when the file size is too large.
  • Fixed Context header values "shifting". Sometimes, the values were not correct.

What's Changed

  • refactor(compose): cache length by @yusukebe in #460
  • fix(ETag): fixed an error when the file size is too large. by @yusukebe in #461
  • refactor(mime): made .ico file's extension to image/x-icon by @yusukebe in #462
  • fix(context): fix header values shifting by @yusukebe in #463

Full Changelog: v2.0.7...v2.0.8

v2.0.7

06 Aug 21:53
Compare
Choose a tag to compare

Summary

  • JSX Middleware performance tuning.
  • A token in the cookie is enabled for JWT Middleware.
  • Fixed the bug for ETag Middleware.

What's Changed

  • feat(jwt): enable token in cookie by @metrue in #441
  • perf(jsx): JSX performance improvement by @usualoma in #444
  • refactor(jsx): Support all the boolean attributes. by @usualoma in #446
  • refactor: make parsedBody type as Body by @yusukebe in #448
  • refactor(utils/html): rename Buffer to StringBuffer by @yusukebe in #449
  • fix(utils/crypto): stringify the parameter which is object in createHash by @yusukebe in #452
  • refactor: add Json type for JSON object by @yusukebe in #453
  • fix(utils/crypto): make Binary and JSON object crypto correct by @yusukebe in #454

Full Changelog: v2.0.6...v2.0.7