What are the differences between these three Guzzle (guzzlehttp/guzzle
) methods:
use Illuminate\Support\Facades\Http;
$response = Http::get('http://example.com');
- $response->ok() : bool;
- $response->successful() : bool;
- $response->failed() : bool;
And when does it make sense to use one of these methods in preference to the other?
Thanks in advance!
CodePudding user response:
These methods come from Laravel
public function successful() { return $this->status() >= 200 && $this->status() < 300; }
public function ok() { return $this->status() === 200; }
public function failed() { return $this->serverError() || $this->clientError(); }
and the differences can be seen with the naked eye
successful() -return true when staus is bettwen 200 , 300
ok() - return true only when status = 200
failed() - return bool if any error
And when does it make sense to use one of these methods in preference to the other?
It depends on the code and the need