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 tonew 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 onlyFormData
by @yusukebe in #487
Full Changelog: v2.0.9...v2.1.0