src/Formio/Service/Base.php
protected function execute(string $method, string $resource, array $options = [])
    {
        $uri = $this->host.$resource;

        if ($this->headers) {
            if (!array_key_exists('headers', $options)) {
                $options['headers'] = [];
            }

            foreach ($this->headers as $key => $value) {
                if (!array_key_exists($key, $options['headers'])) {
                    $options['headers'][$key] = $value;
                }
            }
        }

        // @todo Remove this once we align formio and apip jwt tokens
        unset($options['headers']['Authorization']);

        try {
            $response = $this->client->request($method, $uri, $options);
        } catch (ClientException $exception) {
            $response = $exception->getResponse();

            switch ($response->getStatusCode()) {
                case 400:
                    $validation = new ValidationException('Request is not valid.', 0, $exception);
                    $data = (string) $response->getBody();

                    if ('' !== $data && false !== strpos($data, '{')) {
                        $data = \GuzzleHttp\json_decode($data);

                        if (property_exists($data, 'errors')) {
                            $validation->setErrors((array)$data->errors);
                        } else if (property_exists($data, 'details')) {
                            $validation->setErrors((array)$data->details);
                        }
                    }

                    throw $validation;
                    break;

                default:
                    throw new RequestException('Request failed.', 0, $exception);
            }
        }

        $data = null;

        // @todo Instead of this switch case, refactor execute() method to return header and body, instead of just body.
        switch ($resource) {
            case AuthenticationService::RESOURCE_LOGIN:
                $data = $response->getHeader('x-jwt-token')[0];
                break;

            default:
                $data = (string) $response->getBody();

                if ('' !== $data && false !== strpos($data, '{')) {
                    try {
                        $data = \GuzzleHttp\json_decode($response->getBody());
                    } catch (InvalidArgumentException $exception) {
                        throw new ResponseException('Service response is not valid.', 0, $exception);
                    }
                }
        }

        return $data;
    }
protected function execute(string $method, string $resource, array $options = [])
    {
        $uri = $this->host.$resource;

        if ($this->headers) {
            if (!array_key_exists('headers', $options)) {
                $options['headers'] = [];
            }

            foreach ($this->headers as $key => $value) {
                if (!array_key_exists($key, $options['headers'])) {
                    $options['headers'][$key] = $value;
                }
            }
        }

        // @todo Remove this once we align formio and apip jwt tokens
        unset($options['headers']['Authorization']);

        try {
            $response = $this->client->request($method, $uri, $options);
        } catch (ClientException $exception) {
            $response = $exception->getResponse();

            switch ($response->getStatusCode()) {
                case 400:
                    $validation = new ValidationException('Request is not valid.', 0, $exception);
                    $data = (string) $response->getBody();

                    if ('' !== $data && false !== strpos($data, '{')) {
                        $data = \GuzzleHttp\json_decode($data);

                        if (property_exists($data, 'errors')) {
                            $validation->setErrors((array)$data->errors);
                        } else if (property_exists($data, 'details')) {
                            $validation->setErrors((array)$data->details);
                        }
                    }

                    throw $validation;
                    break;

                default:
                    throw new RequestException('Request failed.', 0, $exception);
            }
        }

        $data = null;

        // @todo Instead of this switch case, refactor execute() method to return header and body, instead of just body.
        switch ($resource) {
            case AuthenticationService::RESOURCE_LOGIN:
                $data = $response->getHeader('x-jwt-token')[0];
                break;

            default:
                $data = (string) $response->getBody();

                if ('' !== $data && false !== strpos($data, '{')) {
                    try {
                        $data = \GuzzleHttp\json_decode($response->getBody());
                    } catch (InvalidArgumentException $exception) {
                        throw new ResponseException('Service response is not valid.', 0, $exception);
                    }
                }
        }

        return $data;
    }
Execute api request

@param string $method
@param string $resource
@param array $options
@return mixed
@throws \Ds\Component\Formio\Exception\RequestException
@throws \Ds\Component\Formio\Exception\ResponseException
@throws \Ds\Component\Formio\Exception\ValidationException