30dd0c5b8d
- 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.
35 lines
898 B
PHP
35 lines
898 B
PHP
<?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);
|
||
}
|
||
} |