We accelerate websites

15 days free trial Sign up

Media Acceleration Stream to the world

15 days free trial Sign up

Extensive Network Excellent world coverage

PHP API integration - an example

An example of API integration using PHP cURL

  1. First we define a function callAPI.

    function callAPI($method, $url, $data = false)
    {
        if(empty($url)) throw new Exception('URL missing');	
        $curl = curl_init();
    
        switch ($method)
        {
            case 'POST':
                curl_setopt($curl, CURLOPT_POST, 1);
    
                if (!empty($data))
                    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
                break;
            case 'PUT':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); 
    		
                if (!empty($data))
                    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));		
    	    break;
            case 'GET':
                if (!empty($data))
                    $url = sprintf('%s?%s', $url, http_build_query($data));
    	    break;
            default: throw new Exception('Unsupported method: ' . $method); 
        }
      
        // Exchange format - JSON
        $headers = array(
                            'Accept: application/json',
                            'Content-Type: application/json',
                        );
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    
        // Authentication:
        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($curl, CURLOPT_USERPWD, 'username:password');
    
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    
        return curl_exec($curl);
    }
    
  2. Now we prepare data which we want to send via API.

    $data = array( 'cdn' => array(
                                    'service_type' => 'HTTP_PULL',
                                    'origin_domain' => 'www.mycompany.com',
                                    'service_domain' => 'cdn.mycompany.com',
                                  )
                 );
    
  3. Finally we perform the API call.

    $response = callAPI('POST', 'https://cdnsun.com/api/cdns', $data);
    

Please refer to API documentation for full description of the API.

 
 ______     _____      _____    ______  
|      \\  |  ___||   / ___//  /_   _// 
|  --  //  | ||__     \___ \\   -| ||-  
|  --  \\  | ||__     /    //   _| ||_  
|______//  |_____||  /____//   /_____// 
`------`   `-----`  `-----`    `-----`  
                                        
Europe
  • Amsterdam
  • Athens
  • Baku
  • Bucharest
  • Budapest
  • Chelyabinsk
  • Copenhagen
  • Dubai
  • Dublin
  • Helsingborg
  • Helsinki
  • Istanbul
  • Khabarovsk
  • Kharkov
  • Kiev
  • Kungalv
  • Lisbon
  • London
  • Lvov
  • Moscow
  • Odessa
  • Oslo
  • Paris
  • Saint Petersburg
  • Stockholm
  • Tel Aviv-Yafo
  • Trondheim
  • Zagreb
America
  • Arlington
  • Atlanta
  • Chicago
  • Dallas
  • Denver
  • Green Bay
  • Los Angeles
  • Miami
  • Montreal
  • New York
  • Phoenix
  • Portland
  • Provo
  • Queretaro
  • Reston
  • Sacramento
  • San Jose
  • Sao Paulo
  • Seattle
  • Toronto
  • Washington
Contact
  • e-mail: info@cdnsun.com
  • skype: cdnsun.com
  • phone: +1 844 300 9206
  • phone: +420 776 256 872
Blog Twitter LinkedIn Facebook CrunchBase Google+ / Google plus Foursquare Pinterest