Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task
H0llyW00dzZ opened this issue May 8, 2024 · 0 comments
Open
1 task

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

H0llyW00dzZ opened this issue May 8, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@H0llyW00dzZ
Copy link
Owner

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.

@H0llyW00dzZ H0llyW00dzZ added the enhancement New feature or request label May 8, 2024
@H0llyW00dzZ H0llyW00dzZ self-assigned this May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

1 participant