🎉 feat: init

This commit is contained in:
saltyaom
2022-11-12 10:09:01 +07:00
commit 768aae730d
16 changed files with 1738 additions and 0 deletions

58
example/index.ts Normal file
View File

@@ -0,0 +1,58 @@
import { KingWorld, t } from 'kingworld'
import swagger from '../src/index'
const app = new KingWorld()
.use(swagger, {
// path: '/v2/swagger',
// swagger: {
// info: {
// title: 'Hello World',
// version: '0.0.0'
// }
// }
})
.get('/', () => 'hi')
.get('/unpath/:id', ({ params: { id } }) => id)
.get('/unpath/:id/:name', ({ params: { id } }) => id)
.post(
'/json/:id',
({ body, params: { id }, query: { name } }) => ({
...body,
id,
name
}),
{
schema: {
params: t.Object({
id: t.String()
}),
query: t.Object({
name: t.String()
}),
body: t.Object({
username: t.String(),
password: t.String()
}),
response: t.Object({
username: t.String(),
password: t.String(),
id: t.String(),
name: t.String()
})
}
}
)
.post('/json', ({ body }) => body, {
schema: {
body: t.Object({
username: t.String(),
password: t.String()
}),
response: t.Object({
username: t.String(),
password: t.String()
})
}
})
.listen(8080)