Skip to content

Commit

Permalink
fix: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvibes committed Feb 2, 2025
1 parent 6d889ac commit d742756
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ to develop APIs and web applications.
`log/slog`, `context` and `html/template`.
- **Routing**: Fuego router is based on Go 1.22 `net/http`, with grouping and
middleware support
- Optional trailing slash handling: Configure whether `/users` and `/users/` should be treated as the same route
- **Serialization/Deserialization**: Fuego automatically serializes and
deserializes JSON, XML and HTML Forms based on user-provided structs
(or not, if you want to do it yourself)
Expand All @@ -67,6 +68,24 @@ to develop APIs and web applications.
`templ` or `gomponents`
- **Adaptors**: [Experimental] Fuego can be used with Gin.

## Configuration

### Trailing Slashes

By default, Fuego treats URLs with and without trailing slashes as distinct routes. You can configure the server to automatically strip trailing slashes using the `WithStripTrailingSlash` option:

```go
s := fuego.NewServer(
fuego.WithStripTrailingSlash(),
)
```

When enabled:

- `/api/users` and `/api/users/` will route to the same handler
- Routes registered with trailing slashes are automatically converted to non-trailing slash versions
- Improves URL consistency across your API

## Examples

### Hello World
Expand Down
18 changes: 14 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,24 @@ func WithLoggingMiddleware(loggingConfig LoggingConfig) func(*Server) {
}
}

// WithStripTrailingSlash enables stripping of trailing slashes from routes and requests
// Default is false.
// WithStripTrailingSlash configures the server to automatically strip trailing slashes from URLs.
// When enabled, requests to paths ending with "/" will be treated the same as their non-trailing
// slash counterparts. For example, "/users/" and "/users" will route to the same handler.
//
// Example:
// This option affects both route registration and incoming requests. When a request comes in with
// a trailing slash, it will be matched against the non-trailing slash route if one exists.

// Example usage:
//
// app := fuego.NewServer(
// s := fuego.NewServer(
// fuego.WithStripTrailingSlash(),
// )

// After enabling:
// - A route registered as "/api/users" will match both "/api/users" and "/api/users/"
// - A route registered as "/api/users/" will be automatically converted to "/api/users"
//
// Note: This option should be set during server initialization as it affects all routes.
func WithStripTrailingSlash() func(*Server) {
return func(s *Server) {
// Add OptionStripTrailingSlash to the default route options
Expand Down

0 comments on commit d742756

Please sign in to comment.