Firing off an HTTP request
use Midnite81\Guardian\Factories\GuardianFactory;
use Midnite81\Guardian\Store\RedisStore;
use Midnite81\Guardian\Rules\RateLimitRule;
use GuzzleHttp\Client;
$guardian = GuardianFactory::create(
'blog-post-1',
new RedisStore($options),
[RateLimitRule::allow(6)->perMinute()],
);
$result = $guardian->send(function () {
$client = new Client();
$response = $client->get('https://jsonplaceholder.typicode.com/posts/1');
return json_decode($response->getBody()->getContents(), true);
});
// $result now contains the decoded JSON responseException Handling
RulePreventsExecutionException
RateLimitExceededException
Store Exceptions
Other Exceptions
Last updated