Skip to content

Commit

Permalink
Add header parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahhafizh committed Sep 16, 2020
1 parent 3c897ef commit d53fde8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/helper.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php

if(!function_exists('curlHelper')) {
function curlHelper($endpoint, $method = 'POST', $payload = [], $log_context = [])
function curlHelper($endpoint, $method = 'POST', $payload = [], $header = [], $log_context = [])
{
$url = env('CURL_BASE_URL', null) . $endpoint;
$payload = !empty($payload) ? $payload : request()->all();
$head = array(
"content-type: application/json"
);
if (!empty($header)) {
$head = array_merge($head, $header);
}

$curl = curl_init();

Expand All @@ -17,9 +23,7 @@ function curlHelper($endpoint, $method = 'POST', $payload = [], $log_context = [
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
CURLOPT_HTTPHEADER => $head,
));

$response = curl_exec($curl);
Expand Down

0 comments on commit d53fde8

Please sign in to comment.