2021-12-15 03:41:28 +01:00
|
|
|
const Hono = require('../../src/hono')
|
|
|
|
const app = Hono()
|
|
|
|
|
|
|
|
// Text
|
|
|
|
app.get('/', () => 'Hono!!')
|
|
|
|
|
|
|
|
// JSON
|
|
|
|
app.get('/api', () => { return { message: 'Hello! from /api' } })
|
|
|
|
|
2021-12-16 09:34:05 +01:00
|
|
|
app.get('/entry', () => 'Get entry')
|
|
|
|
app.post('/entry', () => 'Post entry')
|
|
|
|
|
|
|
|
//app.route('/book')
|
|
|
|
// .get(() => 'Get a random book')
|
|
|
|
// .post(() => 'Add a book')
|
|
|
|
// .put(() => 'Update a book')
|
|
|
|
|
2021-12-15 03:41:28 +01:00
|
|
|
// With original response header
|
|
|
|
app.get('/hello', () => {
|
|
|
|
return new Response('Hello! from /hello', {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'X-Message': 'This is Hono'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-12-16 09:34:05 +01:00
|
|
|
const notFound = () => {
|
|
|
|
return new Response('not found', {
|
|
|
|
status: 404
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
app.get('/not_found', (req) => {
|
|
|
|
notFound()
|
|
|
|
})
|
|
|
|
|
2021-12-15 03:41:28 +01:00
|
|
|
app.fire()
|