Upgrade to Pro — share decks privately, control downloads, hide ads and more …

20241024 Honoにドキュメント増えてた

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for saka saka
December 23, 2025
1

20241024 Honoにドキュメント増えてた

Avatar for saka

saka

December 23, 2025

Transcript

  1. export const app = Hono<BlankEnv, BlankSchema, '/'>().get< 'foo/:id', 'foo/:id', JSONRespondReturn<{

    ok: boolean }, 200>, BlankInput, BlankEnv >('foo/:id', (c) => c.json({ ok: true }, 200))
  2. const app = new Hono().get<'foo/:id'>('foo/:id', (c) => c.json({ ok: true

    }, 200) ) ී௨ͷίʔυ const app = new Hono().get('foo/:id', (c) => c.json({ ok: true }, 200) )
  3. import { app } from './app' import { hc }

    from 'hono/client' // this is a trick to calculate the type when compiling const client = hc<typeof app>('') export type Client = typeof client export const hcWithType = (...args: Parameters<typeof hc>): Client => hc<typeof app>(…args) // ී௨͸ const route = app.post( // লུ ) export type AppType = typeof route
  4. const client = hcWithType('http://localhost:8787/') const res = await client.posts.$post({ form:

    { title: 'Hello', body: 'Hono is a cool project', }, }) // ී௨ const client = hc<AppType>('http://localhost:8787/')
  5. // authors-cli.ts import { app as authorsApp } from './authors'

    import { hc } from 'hono/client' const authorsClient = hc<typeof authorsApp>('/authors') // books-cli.ts import { app as booksApp } from './books' import { hc } from 'hono/client' const booksClient = hc<typeof booksApp>('/books')