<?php
session_start();
function make_post_request($url, $data) {
    $token = $_SESSION['token'];
    $headers = [
        "Authorization: Bearer $token",
        "Content-Type: application/json",
        "Accept: application/json"
    ];

    $options = [
            'http' => [
                'header'  => implode("\r\n", $headers),
                'method'  => 'POST',
                'content' => json_encode($data),
                 'ignore_errors' => true
             ],
         'ssl' => [
             'verify_peer' => false,
                 'verify_peer_name' => false
        ]
        ];

         
     $context  = stream_context_create($options);
    return file_get_contents($url, false, $context);
}



function make_get_request($url, $headers = []) {
    $options = array(
        'http' => array(
            'header'  => array_merge([
                "accept: application/json"
            ], $headers),
            'method'  => 'GET',
            'ignore_errors' => true
        ),
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false
        )
    );

    $context  = stream_context_create($options);
    return file_get_contents($url, false, $context);
}



function make_patch_request($url,$data) {
    $token = $_SESSION['token'];
    $headers = [
        "Authorization: Bearer $token",
        "Content-Type: application/json",
        "Accept: application/json"
    ];

    $options = [
        'http' => [
            'header'  => implode("\r\n", $headers),
            'method'  => 'PATCH',
            'content' => json_encode($data),
             'ignore_errors' => true
         ],
     'ssl' => [
         'verify_peer' => false,
             'verify_peer_name' => false
    ]
    ];

    $context  = stream_context_create($options);
    return file_get_contents($url, false, $context);
}



function make_delete_request($url) {
    $token = $_SESSION['token'];
    $headers = [
        "Authorization: Bearer $token",
    ];

    $options = [
        'http' => [
            'header'  => implode("\r\n", $headers),
            'method'  => 'DELETE',
            'ignore_errors' => true
        ],
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false
        ]
    ];

    $context = stream_context_create($options);
    return file_get_contents($url, false, $context);
}


function make_bulk_delete_request($url,$postData) {
    $token = $_SESSION['token'];
    $headers = [
        "Authorization: Bearer $token",
    ];

    $options = [
        'http' => [
            'header'  => implode("\r\n", $headers),
            'method'  => 'DELETE',
            'content' => json_encode($postData),
            'ignore_errors' => true
        ],
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false
        ]
    ];

    $context = stream_context_create($options);
    return file_get_contents($url, false, $context);
}

?>

