Skip to content

v-hono/v-hono-core

Repository files navigation

v-hono-core

A high-performance V language web framework inspired by Hono.js.

Core Features

  • 🚀 High Performance - Hybrid routing with LRU cache for optimal speed
  • 🎯 Simple API - Clean and intuitive API design
  • 🔧 Flexible Routing - Multiple router implementations (FastRouter, TrieRouter, HybridRouter)
  • 🌐 Multiple Backends - Picoev and uSockets support
  • 🔌 Modular Design - Optional plugins for extended functionality

Installation

v install --git https://github.com/v-hono/v-hono-core

Quick Start

import net.http
import hono

fn main() {
    mut app := hono.Hono.new()

    app.get('/', fn (mut c hono.Context) http.Response {
        return c.text('Hello, World!')
    })

    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}"}')
    })

    app.listen(':3000')
}

High Concurrency Support

v-hono-core with uSockets backend supports 10,000+ concurrent connections out of the box.

import hono

fn main() {
    mut app := hono.Hono.new()
    
    app.get('/', fn (mut c hono.Context) http.Response {
        return c.text('Hello, World!')
    })
    
    // Use uSockets backend for high concurrency
    app.listen_usockets(3000)
}

Build with uSockets:

# macOS / Linux
v -enable-globals -prod -o app your_app.v

# Windows (must use gcc)
v -enable-globals -cc gcc -ldflags "-ldbghelp" -o app.exe your_app.v

Core API

Application

  • Hono.new() - Create a new application
  • app.get(path, handler) - Register GET route
  • app.post(path, handler) - Register POST route
  • app.put(path, handler) - Register PUT route
  • app.delete(path, handler) - Register DELETE route
  • app.patch(path, handler) - Register PATCH route
  • app.all(path, handler) - Register route for all methods
  • app.use(middleware) - Add middleware
  • app.route(prefix, subapp) - Mount sub-application
  • app.listen(port) - Start server with picoev
  • app.listen_usockets(port) - Start server with uSockets

Context

  • c.text(data) - Return text response
  • c.json(data) - Return JSON response
  • c.html(data) - Return HTML response
  • c.file(path) - Return file response
  • c.redirect(url, status...) - Redirect to URL
  • c.status(code) - Set response status code
  • c.params - Route parameters
  • c.query - Query parameters
  • c.body - Request body
  • c.headers - Response headers
  • c.set(key, value) - Store data in context
  • c.get(key) - Retrieve data from context

Optional Libraries

Extend v-hono-core with additional functionality:

Authentication and authorization

  • JWT authentication
  • Bearer token auth
  • User session management
  • Role-based permissions

Common middleware collection

  • CORS
  • Cookie management
  • Request compression
  • Rate limiting
  • Request validation
  • Logging

Static file serving

File upload and storage handling

  • Multipart form parsing
  • Chunked uploads
  • File storage system (SQLite)

Real-time communication

  • WebSocket support
  • Server-Sent Events (SSE)
  • Streaming responses

API documentation

  • OpenAPI 3.0/3.1
  • Swagger UI

Performance Benchmarks

Concurrent RPS Avg Latency Success Rate
5,000 81,524 60.77ms 100%
6,000 56,290 98.46ms 100%
7,000 42,895 130.04ms 100%
10,000 24,198 240.90ms 100%

Project Structure

v-hono-core/          # Core framework
├── app.v        # Application and routing
├── router.v     # Hybrid router
├── fast_router.v # Fast precompiled router
├── trie_router.v # Trie-based router
├── cache.v      # LRU cache
├── request.v    # Request context
├── response.v   # Response utilities
├── security.v   # Security utilities
├── error_handler.v # Error handling
├── picoev_server.v # Picoev backend
├── usockets_server.v # uSockets backend
└── usockets/    # uSockets library

Examples

See the examples/ directory for more examples:

  • examples/basic/ - Basic usage
  • examples/route_grouping/ - Route grouping
  • Server backends (picoev, uSockets)

Documentation

See docs/ directory for detailed documentation:

License

MIT

About

High-performance, lightweight V language web framework core inspired by Hono.js.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors