Skip to content

segu23/cloudflare-sdk-kv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cloudflare-sdk-kv

Usage/Examples

Including the sdk in your project

Maven

	<repository>
		<id>jitpack.io</id>
		<url>https://jitpack.io</url>
	</repository>
	<dependency>
		<groupId>com.github.segu23</groupId>
		<artifactId>cloudflare-sdk-kv</artifactId>
		<version>1.1.2</version>
	</dependency>

Gradle

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}
	dependencies {
	        implementation 'com.github.segu23:cloudflare-sdk-kv:1.0'
	}

Initializing KV service

IWorkerKVService workerKVService = CloudflareKVConfig.builder()
                .setAccountIdentifier("XXXXXXXXXX")
                .setAuthorizationToken("XXXXXXXXXX")
                .setApiKey("XXXXXXXXXX")
                .setApiEmail("XXXXXXXXXX")
                .build();

List Namespaces

ListNamespacesResponse listNamespacesResponse = workerKVService.listNamespaces();

Create a Namespace

CreateNamespaceResponse createNamespaceResponse = workerKVService.createNamespace("namespace-title");

Find Namespace by name

Namespace namespace = workerKVService.findNamespaceByName("namespace-title");

Remove a Namespace

RemoveNamespaceResponse removeNamespaceResponse = workerKVService.removeNamespace(namespace.getId());

Rename a Namespace

RenameNamespaceResponse renameNamespaceResponse = workerKVService.renameNamespace(namespace.getId(), "new-namespace-title");

Delete multiple key-value pairs

DeleteMultipleKeyValuePairsResponse deleteMultipleKeyValuePairsResponse = workerKVService.deleteMultipleKeyValuePairs(namespace.getId(), new String[]{"firstKey", "secondKey"});

Write multiple key-value pairs

WriteMultipleKeyValuePairsResponse writeMultipleKeyValuePairsResponse = workerKVService.writeMultipleKeyValuePairs(namespace.getId(), 
        new KeyValuePair[]{
                new KeyValuePair()
                        .setKey("firstKey")
                        .setValue("example firstKey value")
                        .setMetadata(Map.of(
                            "firstMetadata", "firstMetadata value", 
                            "secondMetadata", "secondMetadata value"
                        )),
                new KeyValuePair()
                        .setKey("secondKey")
                        .setValue("example secondKey value")
        }
);

List a Namespace's Keys

ListNamespaceKeysResponse listNamespaceKeysResponse = workerKVService.listNamespaceKeys(namespace.getId());

Read the metadata for a key

ReadMetadataKeyResponse readMetadataKeyResponse = workerKVService.readMetadataKey(namespace.getId(), "firstKey");

Delete key-value pair

DeleteKeyValuePairResponse deleteKeyValuePairResponse = workerKVService.deleteKeyValuePair(namespace.getId(), "firstKey");

Read key-value pair

String firstKeyValue = workerKVService.readKeyValuePair(namespace.getId(), "firstKey");

Write key-value pair with metadata

WriteKeyValuePairWithMetadataResponse writeKeyValuePairWithMetadataResponse = workerKVService.writeKeyValuePairWithMetadata(namespace.getId(), 
    "firstKey", "firstKeyValue", 
    Map.of(
        "firstMetadata", "firstMetadata value", 
        "secondMetadata", "secondMetadata value"
    )
);

About

Cloudflare Worker KV's Unofficial Java SDK

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages