src/EasyCurl.php
public function query($method = 'get', array $data = [], $uri = null)
    {

        if (null !== $uri) {
            $this->uri = $uri;

            if ($this->curl !== null) {
                curl_close($this->curl);
            }

            $this->curl = curl_init($uri);
        }

        $method = strtoupper($method);

        if (!in_array($method, ['GET', 'POST', 'PUT', 'DELETE'], true)) {
            $method = 'GET';
        }

        if (is_array($data) && empty($data)) {
            $this->unsetHeader('Content-Length');
        }

        $this->setOpt(CURLOPT_CUSTOMREQUEST, $method);

        if ($method === 'GET') {
            $this->setOpt(CURLOPT_HTTPGET, true);
            $this->setOpt(CURLOPT_URL, $this->uri . '?' . http_build_query($data));
            return $this->exec();
        }

        $this->setOpt(CURLOPT_POST, true);

        if ($this->isAutoJSON()) {
            $dataJson = json_encode($data);

            $this->setOpt(
                CURLOPT_HTTPHEADER,
                [
                    'Content-Type: application/json',
                    'Content-Length: ' . strlen($dataJson)
                ]);

            $this->setOpt(CURLOPT_POSTFIELDS, $dataJson);

            return $this->exec();
        }

        $this->setOpt(CURLOPT_POSTFIELDS, http_build_query($data));

        return $this->exec();
    }
public function query($method = 'get', array $data = [], $uri = null)
    {

        if (null !== $uri) {
            $this->uri = $uri;

            if ($this->curl !== null) {
                curl_close($this->curl);
            }

            $this->curl = curl_init($uri);
        }

        $method = strtoupper($method);

        if (!in_array($method, ['GET', 'POST', 'PUT', 'DELETE'], true)) {
            $method = 'GET';
        }

        if (is_array($data) && empty($data)) {
            $this->unsetHeader('Content-Length');
        }

        $this->setOpt(CURLOPT_CUSTOMREQUEST, $method);

        if ($method === 'GET') {
            $this->setOpt(CURLOPT_HTTPGET, true);
            $this->setOpt(CURLOPT_URL, $this->uri . '?' . http_build_query($data));
            return $this->exec();
        }

        $this->setOpt(CURLOPT_POST, true);

        if ($this->isAutoJSON()) {
            $dataJson = json_encode($data);

            $this->setOpt(
                CURLOPT_HTTPHEADER,
                [
                    'Content-Type: application/json',
                    'Content-Length: ' . strlen($dataJson)
                ]);

            $this->setOpt(CURLOPT_POSTFIELDS, $dataJson);

            return $this->exec();
        }

        $this->setOpt(CURLOPT_POSTFIELDS, http_build_query($data));

        return $this->exec();
    }
Performs query

@param string $method
@param array $data
@param string $uri

@return mixed