Skip to content

Enhance API Route & API Group to support multiple handlers #246

@H0llyW00dzZ

Description

@H0llyW00dzZ

TODO:

  • Enhance API Route & API Group to support multiple handlers

Note

It seems possible to Enhance API Route & API Group to support multiple handlers. For example, could use multiple RateLimiter instances in a single API Route or API Group. This is the current structure:

// APIRoute represents a single API route, containing the path, HTTP method,
// handler function, and an optional rate limiter.
type APIRoute struct {
	Path                      string
	Method                    string
	Handler                   fiber.Handler
	RateLimiter               fiber.Handler
	KeyAuth                   fiber.Handler
	RequestID                 fiber.Handler
	EncryptedCookieMiddleware fiber.Handler
}

// APIGroup represents a group of API routes under a common prefix.
// It also allows for a group-wide rate limiter.
type APIGroup struct {
	Prefix                    string
	Routes                    []APIRoute
	RateLimiter               fiber.Handler
	KeyAuth                   fiber.Handler
	RequestID                 fiber.Handler
	EncryptedCookieMiddleware fiber.Handler
}

Example:

	apiGroups := []APIGroup{
		{ // Note: Example https://localhost:8080/v1/server/health/db
			Prefix:      "/server/health",
			RateLimiter: rateLimiterRESTAPIs1, rateLimiterRESTAPIs2,etc // This is an optional example.
			Routes: []APIRoute{
				{
					Path: "/db",
					// Note: This approach allows defining multiple HTTP methods (e.g., GET, POST, PUT, DELETE) for a single handler & path.
					Method: strings.Join([]string{
						fiber.MethodGet,
					}, ","),
					Handler: health.DBHandler(db),
				},
			},
		},
	}

Also note that it is useful for cookies, because cookie values have limited length, especially for encrypting sensitive data.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions