Note: This library is under active development as I expand it to cover Cloudflare API. Consider the public API of this package a little unstable as I work towards a v1.0. See Coverage.

KV

Cloudflare API docs

List Namespaces

Returns the namespaces owned by an account.

php
$response = $client->workers()->kv()->list('account_id');

Create a Namespace

Creates a namespace under the given title. A 400 is returned if the account already owns a namespace with this title. A namespace must be explicitly deleted to be replaced.

php
$response = $client->workers()->kv()->create('account_id', 'title');

Get a Namespace

Get the namespace corresponding to the given ID.

php
$response = $client->workers()->kv()->delete('account_id', 'namespace_id');

Rename a Namespace

Modifies a namespace's title.

php
$response = $client->workers()->kv()->delete('account_id', 'namespace_id', 'title');

Remove a Namespace

Deletes the namespace corresponding to the given ID.

php
$response = $client->workers()->kv()->delete('account_id', 'namespace_id');

Write multiple key-value pairs

Write multiple keys and values at once. Body should be an array of up to 10,000 key-value pairs to be stored, along with optional expiration information. Existing values and expirations will be overwritten. If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored. The entire request size must be 100 megabytes or less.

php
$response = $client->workers()->kv()->writeMultipleKeys('account_id', 'namespace_id');

Delete multiple key-value pairs

Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.

php
$response = $client->workers()->kv()->deleteMultipleKeys('account_id', 'namespace_id', $keys);

List a Namespace Keys

Lists a namespace keys.

php
$response = $client->workers()->kv()->listKeys('account_id', 'namespace_id');

Read the metadata for a key

Returns the metadata associated with the given key in the given namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name.

php
$response = $client->workers()->kv()->keyMetadata('account_id', 'namespace_id', 'key_name');

Read key-value pair

Returns the value associated with the given key in the given namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name. If the KV-pair is set to expire at some point, the expiration time as measured in seconds since the UNIX epoch will be returned in the expiration response header.

php
$response = $client->workers()->kv()->keyDetails('account_id', 'namespace_id', 'key_name');

Write key-value pair with metadata

Write a value identified by a key. Use URL-encoding to use special characters (for example, :, !, %) in the key name. Body should be the value to be stored along with JSON metadata to be associated with the key/value pair. Existing values, expirations, and metadata will be overwritten. If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored.

php
$response = $client->workers()->kv()->writeKeyWithMetadata('account_id', 'namespace_id', 'key_name');

Delete key-value pair

Remove a KV pair from the namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name.

php
$response = $client->workers()->kv()->deleteKey('account_id', 'namespace_id', 'key_name');