Files
v-hono/examples/basic/example.v
T
meiseayoung 3b8d21dd0d fix: update import path to VPM package name (meiseayoung.hono)
- Change all `import hono` to `import meiseayoung.hono` in code and docs
- Ensure compatibility with VPM installation via `v install meiseayoung.hono`
2026-01-02 22:05:12 +08:00

48 lines
1.1 KiB
V

// Basic example of using v-hono web framework
// Run with: v run examples/basic/example.v
// Or after installing: v install your-username.hono
module main
import net.http
import meiseayoung.hono
fn main() {
mut app := hono.Hono.new()
// Basic GET route
app.get('/', fn (mut c hono.Context) http.Response {
return c.text('Hello, World!')
})
// JSON response
app.get('/json', fn (mut c hono.Context) http.Response {
return c.json('{"message": "Hello, JSON!"}')
})
// HTML response
app.get('/html', fn (mut c hono.Context) http.Response {
return c.html('<h1>Hello, HTML!</h1>')
})
// Route with parameters
app.get('/users/:id', fn (mut c hono.Context) http.Response {
user_id := c.params['id'] or { 'unknown' }
return c.json('{"user_id": "${user_id}"}')
})
// Query parameters
app.get('/search', fn (mut c hono.Context) http.Response {
query := c.query['q'] or { '' }
return c.json('{"query": "${query}"}')
})
// POST route
app.post('/api/data', fn (mut c hono.Context) http.Response {
body := c.body
return c.json('{"received": "${body}"}')
})
println('Server starting on http://127.0.0.1:3000')
app.listen(':3000')
}