PHP code example of maximantonisin / spirit-client

1. Go to this page and download the library: Download maximantonisin/spirit-client 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/ */

    

maximantonisin / spirit-client example snippets




use \Symfony\Component\HttpFoundation\Request;

$client = new MaximAntonisin\Spirit\SpiritClient([
    'base_uri' => 'json.maximus.pw',
]);

$client->sendRequest('', Request::METHOD_GET, [
    /** Request options. */
]);

/** @var array $response */
/** Response will contain json_decode-ed as array. */
$response = $client->getContent();



use \Symfony\Component\HttpFoundation\Request;

$client = new MaximAntonisin\Spirit\SpiritAsyncClient([
    'base_uri' => 'json.maximus.pw',
]);

/** Request #1 */
$client->addRequest(Request::METHOD_POST, '', [
    /** Request options. */
]);

/** Request #2 */
$client->addRequest(Request::METHOD_POST, '', [
    /** Request options. */
]);
$client->sendAll();

/** @var array $responses */
/** Responses will contain json_decode-ed responses as array. */
$responses = $client->getContents();



use MaximAntonisin\Spirit\SpiritClient;
use \Symfony\Component\HttpFoundation\Request;

/**
 * ... Class description ...
 *
 * @author Maxim Antonisin <[email protected]>
 *
 * @version 1.0.0
 */
class MyClass extends SpiritClient
{
    /**
     * {@inheridDoc}
     */
    protected $baseUrl = 'json.maximus.pw';

    /**
     * ... Method description ...
     */
    public function myMethod()
    {
        $this->sendRequest('', Request::METHOD_GET, [
            /** Request options. */
        ]);

        /** @var array $response */
        /** Response will contain json_decode-ed as array. */
        $response = $this->getContent();
    }
}

$instance = new MyClass();
$instance->myMethod();



use MaximAntonisin\Spirit\SpiritAsyncClient;
use \Symfony\Component\HttpFoundation\Request;

/**
 * ... Class description ...
 *
 * @author Maxim Antonisin <[email protected]>
 *
 * @version 1.0.0
 */
class MyAsyncClass extends SpiritAsyncClient
{
    /**
     * {@inheridDoc}
     */
    protected $baseUrl = 'json.maximus.pw';

    /**
     * ... Method description ...
     */
    public function myMethod()
    {
        /** Request #1 */
        $this->addRequest(Request::METHOD_POST, '', [
            /** Request options. */
        ]);

        /** Request #2 */
        $this->addRequest(Request::METHOD_POST, '', [
            /** Request options. */
        ]);
        $this->sendAll();

        /** @var array $responses */
        /** Responses will contain json_decode-ed responses as array. */
        $responses = $this->getContents();
    }
}

$instance = new MyAsyncClass();
$instance->myMethod();