HyperServe Examples
This directory contains examples demonstrating various features and use cases of HyperServe.
Examples are numbered to suggest a learning path from simple to complex.
π― Quick Start Path
If you're new to HyperServe, follow this progression:
- hello-world - Your first HyperServe server
- static-files - Serving HTML, CSS, and JavaScript
- json-api - Building a REST API with JSON
- middleware-basics - Adding middleware layer by layer
- configuration - Configuration methods and precedence
π All Examples
Beginner Examples
The simplest possible HyperServe server. Start here!
- Single route returning "Hello, World!"
- Minimal code with detailed comments
- Run:
go run examples/hello-world/main.go
Serve a static website with HyperServe.
- HTML, CSS, and JavaScript files
- Directory structure best practices
- Security headers for static content
- Run:
go run examples/static-files/main.go
Build a REST API with JSON request/response handling.
- CRUD operations for a TODO list
- Request parsing and validation
- Error handling patterns
- Run:
go run examples/json-api/main.go
Learn how middleware works by building up a stack.
- Start with no middleware
- Add logging, rate limiting, CORS step by step
- Understand middleware ordering and composition
- Run:
go run examples/middleware-basics/main.go
Master HyperServe's configuration system.
- Environment variables
- JSON configuration files
- Programmatic options
- Configuration precedence
- Run:
go run examples/configuration/main.go
auth βββ
Token-based authentication (Coming Soon).
- Bearer token validation
- Protected vs public routes
- Custom validators
- Status: TODO
Test your application's resilience with chaos engineering.
- Simulated failures and latency
- Load testing with concurrent clients
- Observability during chaos
- Run:
go run examples/chaos/main.go
Advanced Examples
Dynamic web applications with HTMX.
- Server-side rendering with templates
- HTMX attributes for interactivity
- No JavaScript framework needed
- Run:
go run examples/htmx-dynamic/main.go
Real-time updates with Server-Sent Events.
- SSE for live data streaming
- HTMX integration for UI updates
- Graceful connection handling
- Run:
go run examples/htmx-stream/main.go
Enterprise-grade security features (Go 1.24+ required).
- FIPS 140-3 compliance
- TLS with ECH (Encrypted Client Hello)
- Post-quantum cryptography
- Full security middleware stack
- Setup: See enterprise/README.md for certificate generation
- Run:
cd examples/enterprise && ./generate_certs.sh && go run main.go
mcp ββββ
Model Context Protocol (MCP) support for AI assistants.
- JSON-RPC 2.0 protocol implementation
- Built-in tools (calculator, file operations, HTTP)
- Built-in resources (config, metrics, system info)
- Secure sandboxed file access
- Run:
go run examples/mcp/main.go
π Running Examples
All examples can be run directly:
# From the project root
go run examples/hello-world/main.go
# Or navigate to the example directory
cd examples/hello-world
go run main.go
Most examples run on port 8080 by default. The enterprise example uses 8443 for HTTPS.
π Testing Examples
Each example can be tested with curl:
# Hello World
curl http://localhost:8080/
# Static Files
curl http://localhost:8080/index.html
# JSON API
curl -X POST http://localhost:8080/todos \
-H "Content-Type: application/json" \
-d '{"title":"Learn HyperServe"}'
π Learning Tips
-
Start Simple: Don't jump to advanced examples. The progression is designed to build on previous concepts.
-
Read the Code: Each example has extensive comments explaining not just what the code does, but why.
-
Experiment: Modify the examples. Break things. Change configurations. This is how you learn!
-
Check the Logs: HyperServe has excellent logging. Run with HS_LOG_LEVEL=debug for more details.
-
Use the Docs: Refer to the main README.md and docs/ for deeper explanations.
π€ Contributing
Have an idea for a new example? Please contribute! Good examples should:
- Demonstrate a specific HyperServe feature or use case
- Include clear comments explaining the code
- Have a README with setup instructions if needed
- Be as simple as possible while still being realistic
- Include curl commands or a simple client to test with
π Example Template
When creating a new example, consider this structure:
examples/your-example/
βββ README.md # What it does, how to run it, what to learn
βββ main.go # Well-commented implementation
βββ static/ # (optional) Static assets
βββ templates/ # (optional) HTML templates
βββ client/ # (optional) Test client or curl commands
Happy learning! π