npm hono 3.7.0
v3.7.0

latest releases: 4.6.9, 4.6.8, 4.6.7...
13 months ago

Hono v3.7.0 is out now! Let's take a look at the new features.

c.stream() and c.streamText()

We added the awaited functionality related to streaming. c.stream() and c.streamText().

You can easily create HTTP Streaming endpoints with them.

app.get('/', (c) => {
  return c.streamText(async (stream) => {
    stream.writeln('Hello!')
    await stream.sleep(1000)
    stream.writeln('Hono!')
  })
})

You know Streaming works well with AI. With streamText() you can write your ChatGPT Gateway in elegant code.

app.post('/api', async (c) => {
  const body = await c.req.json<{ message: string }>()

  const openai = new OpenAI({ apiKey: c.env.OPENAI_API_KEY })
  const chatStream = await openai.chat.completions.create({
    messages: PROMPT(body.message),
    model: 'gpt-3.5-turbo',
    stream: true
  })

  return c.streamText(async (stream) => {
    for await (const message of chatStream) {
      await stream.write(message.choices[0]?.delta.content ?? '')
    }
  })
})

This application can display streamed data from OpenAI's API in a flowing manner.

Screen.Recording.2023-09-21.at.11.11.36.mov

Thanks, @sor4chi and @geelen !

Testing Helper

With testClient in Testing Helper you can easily write your tests. The object returned by this function is the hc client, so you can define your request with the editor completion.

import { testClient } from 'hono/testing'

it('test', async() => {
  const app = new Hono().get('/search', (c) => c.jsonT({ hello: 'world' }))
  const res = await testClient(app).search.$get()

  expect(await res.json()).toEqual({ hello: 'world' })
})
sc.mov

Thanks, @hagishi !

JWT helper

We uses JWT functions internally, but now they are exported as JWT Helper. You can import and use them.

import { decode, sign, verify } from 'hono/jwt'

Thanks, @julianpoma !

All Updates

New Contributors

Full Changelog: v3.6.3...v3.7.0

Don't miss a new hono release

NewReleases is sending notifications on new releases.