Last active
December 10, 2022 00:52
-
-
Save yusukebe/b9476360cc08e92e430fc87936bda7fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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