Skip to content

Conversation

@frontmesh
Copy link
Owner

Feature: Local KV Instance Support

Problem

When running wrangler dev for local development, users had no way to easily post data to the local KV instance. The namespace ID is the same for both local and remote, making it confusing which endpoint is being used.

Solution

Add a --local / -l flag that switches between local and remote KV endpoints:

  • Local (with -l): http://localhost:8787 (wrangler dev)
  • Remote (without -l): https://api.cloudflare.com/client/v4 (production)

Usage Examples

# Local development (wrangler dev must be running)
cfkv -l put mykey --value "test"
cfkv -l get mykey
cfkv -l list

# Production (default)
cfkv put mykey --value "production"
cfkv get mykey

Changes

  • ✅ Added --local / -l flag to CLI
  • ✅ Updated ClientConfig to support local/remote switching
  • ✅ Added 3 new tests for local/remote endpoint switching
  • ✅ Added comprehensive development guide in docs/LOCAL_KV_DEVELOPMENT.md
  • ✅ All tests pass (57 passed, 0 failed)
  • ✅ Clippy passes with no warnings
  • ✅ Code formatting verified with rustfmt

Prerequisites

  • wrangler dev must be running for local operations
  • Uses same credentials as production KV (token may not be validated for local)

Testing

  • Unit tests verify correct endpoint switching behavior
  • Tests cover both local and remote endpoint configurations
  • No existing tests were broken

Files Changed

  • crates/cloudflare-kv/src/types.rs - Added is_local and base_url() method
  • crates/cloudflare-kv/src/client.rs - Added local/remote endpoint tests
  • crates/cfkv/src/cli.rs - Added --local flag to CLI
  • crates/cfkv/src/main.rs - Apply local flag to KvClient config
  • docs/LOCAL_KV_DEVELOPMENT.md - New comprehensive development guide

- Add support for switching between local and remote KV instances
- Local KV defaults to http://localhost:8787 (wrangler dev default)
- Remote KV uses https://api.cloudflare.com/client/v4 (production API)
- Add -l/--local flag to CLI for easy switching
- Update ClientConfig with is_local field and base_url() method
- Add tests for local/remote endpoint switching
- All existing tests pass
@frontmesh frontmesh closed this Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants