Skip to content

Comments

Add json helper method to set payload as json-encoded value.#147

Merged
LukeTowers merged 6 commits intodevelopfrom
set-payload
Aug 2, 2023
Merged

Add json helper method to set payload as json-encoded value.#147
LukeTowers merged 6 commits intodevelopfrom
set-payload

Conversation

@mjauvin
Copy link
Member

@mjauvin mjauvin commented May 9, 2023

Allows doing this:

$payload = [
    'key1' => 'value1',
    'key2' => 'value2'
];

$apiResult = Http::post($url, function ($http) use ($payload) {
    $http->json( $payload );
});

Instead of this:

$payload = [
    'key1' => 'value1',
    'key2' => 'value2'
];

$apiResult = Http::post($url, function ($http) use ($payload) {
    $http->header('Content-Type', 'application/json; charset=utf-8');
    $http->setOption( CURLOPT_POSTFIELDS, json_encode($payload) );

@mjauvin mjauvin requested review from LukeTowers and bennothommo May 9, 2023 12:33
@mjauvin mjauvin self-assigned this May 9, 2023
@bennothommo bennothommo added this to the v1.2.3 milestone May 9, 2023
@mjauvin mjauvin changed the title Add the option to set the full payload as json-encoded value Add json helper method to set payload as json-encoded value. May 9, 2023
@LukeTowers LukeTowers modified the milestones: v1.2.3, v1.2.4 Jul 7, 2023
@mjauvin
Copy link
Member Author

mjauvin commented Jul 28, 2023

Any objection to merge this one ?

@LukeTowers LukeTowers merged commit ce542ac into develop Aug 2, 2023
@LukeTowers LukeTowers deleted the set-payload branch August 2, 2023 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants