Skip to content

Examples

Complete working examples to get you started with Marten.

Available Examples

REST API

Build a complete CRUD API with validation, error handling, and proper HTTP semantics.

Authentication

JWT-based authentication with protected routes and token validation.

File Server

Serve static files using wildcard routes and the Static middleware.

Microservices

Patterns for building microservices with Marten — health checks, tracing, graceful shutdown, async jobs.

Running the Bundled Examples

All examples are in the examples/ directory of the repository:

cd examples/basic
go run main.go

Quick Reference

Example Highlights
basic Hello World, JSON, path and query params
crud-api CRUD, validation, Created, NoContent
auth-jwt JWT auth, Bearer token, protected groups
middleware All built-in middleware in one app
groups Route groups, API versioning
error-handling Custom error types and OnError handler
file-server Static files, SPA fallback
marten-demo Full web app with templates and auth