https://github.com/initdc/workers-kv-api
api implementation to manage Cloudflare Workers KV
https://github.com/initdc/workers-kv-api
api cloudflare kv workers
Last synced: 12 months ago
JSON representation
api implementation to manage Cloudflare Workers KV
- Host: GitHub
- URL: https://github.com/initdc/workers-kv-api
- Owner: initdc
- License: mit
- Created: 2021-09-27T00:54:20.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-02T19:35:01.000Z (almost 4 years ago)
- Last Synced: 2025-01-20T23:48:29.581Z (about 1 year ago)
- Topics: api, cloudflare, kv, workers
- Language: JavaScript
- Homepage: https://api.m02.link/v2
- Size: 37.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Workers-KV-api
> api implementation to manage Cloudflare Workers KV
## Notice
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.
## Design
```js
api.example.com / v1 / db / test;
/*
@v1: api version
@db: api service
@test: key
*/
```
## Methods
- `POST` & `PUT` methods example
```js
/*
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"}'
```
## Deploy
1. create a worker
2. paste the code from `api.js`
3. set KV database binding
4. create records in KV database
5. set route for `api.example.com`
6. create DNS record for `api.example.com`
## Reference
[Workers KV API reference](https://developers.cloudflare.com/workers/runtime-apis/kv)
## Powered by
[Cloudflare Workers](https://workers.dev/)
## License
MIT