Not sure about guzzle, but in axios js you can have a custom function and return whether body or query.
Or just use body for both if possible.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am working with two different APIs, both using GET requests but handling request data differently:
API 1 requires the data to be sent in the request body, even though the HTTP method is GET.
Example:
$config = [
'method' => 'GET',
'url' => 'http://example.com/api/endpoint',
'headers' => [
'Content-Type' => 'application/json',
],
'body' => [
'key1' => 'value1',
'key2' => 'value2',
],
];
API 2 requires the data to be sent as query parameters in the URL.
Example:
$config = [
'method' => 'GET',
'url' => 'http://example.com/api/endpoint',
'headers' => [
'Content-Type' => 'application/json',
],
'query' => [
'key1' => 'value1',
'key2' => 'value2',
],
];
Both APIs work with the GET method, but their requirements for passing data are different. This makes it challenging to decide when to use query parameters and when to use the request body for a GET request.
Questions:
query) or the request body (body) for a GET request?GET request to accept data in the body, even though the HTTP specification discourages it?Any guidance, best practices, or examples would be appreciated!
Please or to participate in this conversation.