api implementation to manage Cloudflare Workers KV
The Workers includes limited KV Usage. When adding KV records from the offical website, it's doing read function for lots times, it's expensive to do such behavior.
This api has GET
POST
PUT
DELETE
OPTIONS
methods, for public use, you can comment code block
of some methods to protect your data.
api.example.com / v1 / db / test;
/*
@v1: api version
@db: api service
@test: key
*/
POST
&PUT
methods example
/*
header 'Content-Type' can be ignored
@value
*/
/*
@db service
@path: /v1/db
@methods: GET POST PUT DELETE
*/
curl -X "POST" "http://localhost:8787/v1/db/a" -d '{"value": "apple"}'
curl -X "PUT" "http://localhost:8787/v1/db/ab" -d '{"value": "a banana"}'
/*
@search service
@path: /v1/search
@methods: GET
*/
curl -X "GET" "http://localhost:8787/v1/search/a"
/*
!!Danger Zone
move = db (DELETE + POST/PUT)
@move service
@path: /v1/move
@methods: PUT
*/
curl -X "PUT" "http://localhost:8787/v1/move/a" -d '{"newKey": "bpple", "value": "a banana"}'
-
create a worker
-
paste the code from
api.js
-
set KV database binding
-
create records in KV database
-
set route for
api.example.com
-
create DNS record for
api.example.com
MIT