novatorgroup/service1c

Component for executing requests to HTTP Services 1C

Installs: 153

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

1.2.2 2023-01-20 09:36 UTC

This package is auto-updated.

Last update: 2024-04-20 12:37:46 UTC


README

Component for executing requests to HTTP Services 1C

Installation

The preferred way to install this extension is through composer. Either run

php composer.phar require --prefer-dist novatorgroup/service1c "*"

or add

"novatorgroup/service1c": "*"

to the require section of your composer.json file.

Usage

    $service = new \novatorgroup\service1c\HttpService([
        'host' => 'http://host.com', //required
        'base' => 'base', //required
        'login' => 'login',
        'password' => 'password',
        '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"
        ]    
    }