PHP code example of novatorgroup / service1c

1. Go to this page and download the library: Download novatorgroup/service1c library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

novatorgroup / service1c example snippets


    $service = new \novatorgroup\service1c\HttpService([
        'host' => 'http://host.com', //d',
        'curlOptions' => [
            CURLOPT_CONNECTTIMEOUT_MS => 200,
            CURLOPT_TIMEOUT_MS => 1000,
        ]
    ]);

    // GET
    // Request to: // http://host.com/base/hs/command/param?key=value
    
    $response = $service->get('command', ['param', 'key' => 'value']);

    if ($response->isOk()) {
        echo $response->code;
        echo $response->error;
        echo $response->result;
        echo $response->getHeader('Content-Length');
    }
    
    // POST
    // the body will be sent in JSON format
    $response = $service->post('command', ['param' => 'value1', 'param2' => ['a', 'b']]);
    
    // JSON
    {
        "param": "value1",
        "param2": [
            "a",
            "b"
        ]    
    }
    

php composer.phar