Roamer Examples
October 12, 2025 ยท View on GitHub
This directory contains practical examples of using the Roamer HTTP request parsing library.
Basic Examples
- basic - Simple usage examples to get started
cmd/simple/main.go- Basic request parsingcmd/middleware/main.go- Using roamer as middleware
Router Integration Examples
- chi_router - Integration with Chi router
- gorilla_router - Integration with Gorilla Mux
- httprouter - Integration with HttpRouter
Content Type Examples
- json - Working with JSON requests
- xml - Working with XML requests
- form - Working with URL-encoded forms
- multipart - Working with multipart form data (file uploads)
Formatter Examples
- formatters - Using built-in formatters
- String formatting (trim, case conversion, etc.)
- Numeric constraints (min, max, rounding)
- Time manipulation (timezone, truncation)
- Slice operations (unique, sort, limit)
Advanced Examples
-
custom_parser - Creating custom parsers for extracting data from request context
- Implementing the
roamer.Parserinterface - Extracting member/user data injected by middleware
- Type conversion support (string, UUID, struct, pointer)
- Real-world pattern for authentication and authorization data
- Implementing the
-
custom_decoder - Creating custom decoders for YAML content type
- Implementing the
roamer.Decoderinterface - Adding support for custom content types beyond JSON/XML/Form
- Processing complex nested YAML structures
- Implementing the
-
custom_formatter - Creating custom formatters for phone numbers
- Implementing the
roamer.Formatterinterface - Domain-specific data transformations (E.164 phone format)
- Processing formatter tag operations
- Implementing the
-
body_preservation - Reading request body multiple times
- Using
roamer.WithPreserveBody()option - Logging and validating bodies before parsing
- Understanding when body preservation is necessary
- Using
Running Examples
Each example directory contains a complete, runnable Go application. To run an example:
# Simple parsing example
cd examples/basic/cmd/simple
go run main.go
# Router integration example
cd examples/chi_router
go run main.go
# Formatters example
cd examples/formatters
go run main.go
Then in another terminal, test with curl (see each example's output for specific commands).