Skip to content

v-hono/v-hono-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hono_middleware

Middleware collection for v-hono-core framework.

Features

  • CORS - Cross-Origin Resource Sharing
  • Cookie - Cookie parsing and management with signed cookies
  • Compress - Gzip and deflate response compression
  • Rate Limit - Request rate limiting
  • Validator - Schema-based request validation
  • Logger - Request logging

Installation

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

Usage

CORS Middleware

import hono
import hono_middleware

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

    app.use(hono_middleware.cors(hono_middleware.CorsOptions{
        origin: 'https://example.com'
        credentials: true
        allow_methods: ['GET', 'POST', 'PUT', 'DELETE']
    }))

    app.listen(':3000')
}

Rate Limiting

import hono
import hono_middleware

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

    app.use(hono_middleware.rate_limit(hono_middleware.RateLimitOptions{
        store: store
        window_ms: 60000   // 1 minute
        limit: 100         // Max 100 requests
    }))

    app.listen(':3000')
}

Request Validation

import hono
import hono_middleware

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

    app.post('/users',
        hono_middleware.validate_json(hono_middleware.v_object({
            'name': hono_middleware.v_string().required().min(2)
            'email': hono_middleware.v_string().required()
        })),
        fn (mut c hono.Context) http.Response {
            return c.json('{"message":"User created"}')
        }
    )

    app.listen(':3000')
}

Dependencies

  • hono - Core framework

License

MIT

About

Essential middleware collection for v-hono, including CORS, Logger, Validator, and more.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors