Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions rate_limiter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,15 @@ the number of requests to the API::
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
use Symfony\Component\RateLimiter\RateLimiterFactory;

class ApiController extends AbstractController
{
// if you're using service autowiring, the variable name must be:
// "rate limiter name" (in camelCase) + "Limiter" suffix
public function index(RateLimiterFactory $anonymousApiLimiter)
public function index(Request $request, RateLimiterFactory $anonymousApiLimiter)
{
// create a limiter based on a unique identifier of the client
// (e.g. the client's IP address, a username/email, an API key, etc.)
Expand Down Expand Up @@ -272,12 +273,13 @@ the :class:`Symfony\\Component\\RateLimiter\\Reservation` object returned by the
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\RateLimiter\RateLimiterFactory;

class ApiController extends AbstractController
{
public function index(RateLimiterFactory $anonymousApiLimiter)
public function index(Request $request, RateLimiterFactory $anonymousApiLimiter)
{
$limiter = $anonymousApiLimiter->create($request->getClientIp());
$limit = $limiter->consume();
Expand Down