saloon
saloon copied to clipboard
Added isJson and isXML functions to Response class
Two new functions have been added to check if the response return is json or xml
This could be really useful; in a lot of my Connectors, I do things like this:
public function hasRequestFailed(Response $response): ?bool
{
// if psr response is json
$contentType = $response->getPsrResponse()->getHeader('Content-Type');
if (in_array('application/json', $contentType)) {
return ! empty($response->json('errors'));
}
return null;
}
This PR would simplify it like this:
public function hasRequestFailed(Response $response): ?bool
{
if ($response->isJson()) {
return ! empty($response->json('errors'));
}
return null;
}
I would argue, though, that I prefer a more strict comparison than str_contains() proposed in this PR.
@SRWieZ Thank you for your support.
I'm going to have a Saloon day this weekend so I'll merge it then, thanks for the patience!
Glad to see you back!
And thank you for all the work you put into Saloon.