public function createResource(Resource $metadata, $data = '',
                                   string $path = '', string $method = 'POST'): FedoraResource {
        if (!in_array($method, array('POST', 'PUT'))) {
            throw new BadMethodCallException('method must be PUT or POST');
        }
        $baseUrl = $this->txUrl ? $this->txUrl : $this->apiUrl;
        $path    = $path ? $this->sanitizeUri($path) : $baseUrl . $this->defaultCollection;
        $request = new Request($method, $path);
        $request = self::attachData($request, $data);
        try {
            $resp = $this->sendRequest($request);
        } catch (ClientException $e) {
            if (strpos($e->getMessage(), 'tombstone resource') === false) {
                throw $e;
            }
            throw new Deleted();
        }
        $uri = $resp->getHeader('Location')[0];
        $res = $this->getResourceByUri($uri);

        // merge the metadata created by Fedora (and Doorkeeper) upon resource creation
        // with the ones provided by user
        $curMetadata = $res->getMetadata()->merge($metadata, array(RC::idProp()));
        $res->setMetadata($curMetadata);
        $res->updateMetadata();

        return $res;
    }