If you are interfacing with a REST API via PHP, cURL is a convenient and easy way send and receive CRUD (Create, Read, Update, Delete) requests. In order for this to work properly, you need to ensure certain parameters are configured properly, including:

  • Content Type
  • Customer Headers
  • Request Methods
  • Request Data (applies to POST, PUT, DELETE methods)

The following is a basic example of

$ch = curl_init('');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");                                   
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',
    'token: EN3RHT2HFH3NSKGH8F9382NSKDFN2AG9GH0',
    'Content-Length: ' . strlen($data_string))                                                                       

$result = curl_exec($ch);

Additional Resources

Client URL Library

Basic cURL Examples

Using cURL for Remote Requests

Curl and PHP - how can I pass a json through curl by PUT,POST,GET

Example GET, POST, PUT and DELETE requests