Skip to content

feat: Add #[Throttle] Attribute for Rate Limiting#206

Merged
techmahedy merged 1 commit intodoppar:3.xfrom
techmahedy:techmahedy-3.x
Mar 5, 2026
Merged

feat: Add #[Throttle] Attribute for Rate Limiting#206
techmahedy merged 1 commit intodoppar:3.xfrom
techmahedy:techmahedy-3.x

Conversation

@techmahedy
Copy link
Member

@techmahedy techmahedy commented Mar 5, 2026

Adds a new #[Throttle] attribute for declarative rate limiting on controller methods, providing a modern alternative to docblock annotations and route-level rate limit parameters.

Currently, Doppar supports rate limiting through:

  • Docblock annotations - @RateLimit 60/1
  • Route attribute parameters - #[Route('/api/users', rateLimit: 60)]

This PR introduces a new #[Throttle] attribute for declarative rate limiting on controller methods.

Before (Docblock Annotation)

/**
 * Search API endpoint
 * 
 * @RateLimit 60/1
 */
#[Route('/api/search', methods: ['GET'])]
public function search(Request $request)
{
    return SearchService::query($request->input('q'));
}

Before (Route Attribute Parameter)

#[Route('/api/search', methods: ['GET'], rateLimit: 60, rateLimitDecay: 1)]
public function search(Request $request)
{
    return SearchService::query($request->input('q'));
}

Before (With Middleware)

#[Route('/api/search', methods: ['GET'], middleware: ['throttle:60,1'])]
public function search(Request $request)
{
    return SearchService::query($request->input('q'));
}

After (New #[Throttle] Attribute)

#[Route('/api/search', methods: ['GET'])]
#[Throttle(maxAttempts: 10, decayMinutes: 1)]
public function search(Request $request)
{
    return SearchService::query($request->input('q'));
}

Result: 10 requests per minute

In a future major version, we may deprecate docblock annotations and route parameters in favor of attributes.

@techmahedy techmahedy merged commit b4d7668 into doppar:3.x Mar 5, 2026
27 checks passed
@techmahedy techmahedy added the feat new feature label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant