examples/

directory
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT

README

HyperServe examples

Each subdirectory is a self-contained main package. Run with go run ./examples/<name>.

Getting started

Example What it shows
hello-world The smallest possible server — one route, default options.
static-files Serving HTML/CSS/JS with security headers.
json-api Method-aware CRUD API using bounded BindJSON input and structured errors.
middleware-basics Default middleware plus global security headers and route-scoped rate limiting.
configuration Explicit JSON/environment binding and left-to-right option precedence.
binding BindJSON/BindQuery/BindForm + struct-tag validation, with structured 400 responses.

HTMX / templating

Example What it shows
htmx-dynamic Server-rendered templates with HTMX-driven partial updates.
htmx-stream Live HTMX updates over Server-Sent Events.

Auth & enterprise

Example What it shows
auth JWT (RS256), API keys, Basic auth, per-token rate limiting, RBAC.
enterprise FIPS-approved TLS cipher suites + post-quantum key exchange. Generate certs first (./generate_certs.sh).

MCP (Model Context Protocol)

Example What it shows
mcp-basic Smallest MCP server: enable, expose built-in tools/resources.
mcp-cli An MCP server configured by application-owned flags for HTTP or stdio.
mcp-sse Deprecated routed-SSE compatibility, with the required explicit opt-in.
mcp-stdio MCP over stdio for embedding in editors / process-supervised hosts.
mcp-discovery /.well-known/mcp.json discovery with policy filtering.
mcp-extensions Custom MCP tools and resources beyond the built-ins.

Operations / lifecycle

Example What it shows
deferred-init WithDeferredInit + WithOnReady — serve /healthz while bootstrap runs.
devops Health endpoints + metrics + graceful shutdown wired together.
best-practices Idiomatic patterns: error handling, logging, structured config.
complete Multiple features in one binary, useful as a reference implementation.

WebSocket / browser

Example What it shows
websocket-demo Server-tracked RFC 6455 upgrade, bounded echo loop, and embedded browser client.
web-worker-csp WithCSPWebWorkerSupport() for blob:-URL Web Workers (Tone.js, PDF.js, etc.).

Running

go run ./examples/hello-world

Most examples listen on :8080. The enterprise example uses :8443 for HTTPS and requires generated certs.

Test a running example with curl:

curl http://localhost:8080/

Directories

Path Synopsis
Package main demonstrates best practices for using serverpkg.
Package main demonstrates best practices for using serverpkg.
Example: request binding + validation, three ways.
Example: request binding + validation, three ways.
Deferred-init example.
Deferred-init example.
Example demonstrating DevOps features: debug logging and MCP resources
Example demonstrating DevOps features: debug logging and MCP resources
Enterprise example demonstrating FIPS 140-3 compliance and enhanced security features
Enterprise example demonstrating FIPS 140-3 compliance and enhanced security features
Smallest MCP-enabled HyperServe binary: built-in MCP tools/resources, a custom tool, a custom resource, and a sandboxed file-tool root.
Smallest MCP-enabled HyperServe binary: built-in MCP tools/resources, a custom tool, a custom resource, and a sandboxed file-tool root.
Example: Using command-line flags to configure MCP
Example: Using command-line flags to configure MCP
Example: typed MCP tools — one tool per verb.
Example: typed MCP tools — one tool per verb.
Example: legacy HyperServe routed SSE.
Example: legacy HyperServe routed SSE.
Package main demonstrates hyperserve's MCP support as a stdio server for Claude Desktop.
Package main demonstrates hyperserve's MCP support as a stdio server for Claude Desktop.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL