Files
finance/app/Http/Middleware/CustomThrottleRequests.php
T
Ümit Tunç 30dd0c5b8d Enhance currency and gold rates API with custom throttling and improved responses
- Implemented a custom throttle middleware to limit requests to 2 per 30 seconds, enhancing API stability.
- Updated API responses to include Turkish messages for successful updates and error handling.
- Refactored the CurrencyController to integrate the new throttling logic and improve response clarity.
- Enhanced the Scribe documentation to reflect changes in API behavior and response formats.
- Updated views to improve branding and user experience, including dynamic content adjustments.

These changes collectively improve the API's performance, usability, and branding for the Truncgil Finance application.
2025-01-21 18:28:39 +03:00

35 lines
898 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Cache\RateLimiter;
use Symfony\Component\HttpFoundation\Response;
class CustomThrottleRequests
{
protected $limiter;
public function __construct(RateLimiter $limiter)
{
$this->limiter = $limiter;
}
public function handle(Request $request, Closure $next, $maxAttempts = 60, $decayMinutes = 1): Response
{
$key = $request->ip();
if ($this->limiter->tooManyAttempts($key, $maxAttempts)) {
return response()->json([
'error' => 'Rate limit aşıldı',
'message' => 'Bu endpoint 30 dakikada bir kez çağrılabilir.',
'retry_after' => $this->limiter->availableIn($key)
], 429);
}
$this->limiter->hit($key, $decayMinutes * 60);
return $next($request);
}
}