Skip to content

Instantly share code, notes, and snippets.

@yusukebe
Last active December 10, 2022 00:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yusukebe/b9476360cc08e92e430fc87936bda7fa to your computer and use it in GitHub Desktop.
Save yusukebe/b9476360cc08e92e430fc87936bda7fa to your computer and use it in GitHub Desktop.
import { Client } from '../../../src/middleware/client'
import type { AppType } from './server'
const client = new Client<AppType>('http://127.0.0.1:8787/api')
const res = await client.json('/posts', {
id: 123,
title: 'hello',
})
console.log(res)
console.log(await client.get('/hello'))
import { Hono } from '../../../src/index'
import { validator } from '../../../src/middleware/validator'
const api = new Hono()
const getRoute = api
.get('/hello', (c) => {
return c.jsonT({
message: 'hello',
})
})
.build()
const postRoute = api
.post(
'/posts',
validator((v) => ({
id: v.json('id').asNumber(),
title: v.json('title'),
})),
(c) => {
const post = c.req.valid()
return c.jsonT({ title: post.title })
}
)
.build()
export type AppType = typeof postRoute & typeof getRoute
const app = new Hono()
app.route('/api', api)
export default app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment