whinee / kv

Cloudflare KV Rest API (???)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kv

Cloudflare KV Rest API (???)


Cloudflare KV(Key-Value) REST(REpresentational State Transfer) API(Application Programming Interface) (???)


Github: github.com/whinee/kv

Website: whine.is-a.dev/p/w/kv

REST API: kv.wya.workers.dev

Important

This project is a work in progress, use at your own risk.

Also, look at the acronym. Do you think I am to be trusted in this stuff, huh?

Heck, I do not even know what I'm doing, but it works. It fricking works! Crazy, right?

Usage

Write

POST /modify

header content
Content-Type application/json

Example Data:

{"key": "value"}

Response/s:

  • 200 Key-value pair succesfully modified.
    Modified.
  • 401
    • Authorization needed for this endpoint.
      Authorization needed.
    • Invalid credentials.
      • Invalid username.
      • Invalid password.
  • 405 Only use `POST` method at this endpoint.
    POST method only.

Read

GET /a/{key}

Response/s:

  • 200
    {value}

Example Scripts

There are some example scripts in /examples directory. At the moment, there is only python scripts.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

  • git

    To check that you have git installed, in your preferred terminal, run the following command:
    git --version

    If it doesn't throw an error, then you're good to go!

  • npm

    To check that you have npm installed, in your preferred terminal, run the following command:
    npm version

    If it doesn't throw an error, then you're good to go!

Setup

  • Sign up for Cloudflare Workers account.

  • In your preferred terminal, run the following command:

    git clone https://github.com/whinee/kv.git
    cd kv
    npm i -g @cloudflare/wrangler
    echo y | wrangler login

    This will open a browser window.

  • Focus on the browser by hovering the cursor over the said window and clicking on it. A prompt like the following should appear:

    Read all the terms and agree to it by clicking the blue "Allow" button.

    Upon agreeing, after waiting for a moment, the following should appear:

  • Go at Cloudflare Workers Dashboard, and click the dropdown button next to the "Workers" button in the sidebar as shown below:

    It should reveal three more items as show below:

    Click "KV". You should be greeted by the following:

    Click the "Create namespace" button. A popup should greet you as shown below:

    Input the name of the namespace in the "namespace name" field. For this tutorial, we will use the name "test". Click "add". Now, you should see that the namespace "test" is now listed on the table as shown on the following image:

    Hover on the id of the said namespace and you should see a copy icon like shown below:

    Click the icon.

  • Go back to your terminal and run the following command:

    wrangler secret put USER
    wrangler secret put PASS

    For the first prompt, enter the user for the kv. For the second one, the password of the user.

  • Open your text editor of choice and open wrangler.toml, and edit the following lines:

    kv_namespaces = [
    { binding = "KV", id = "dc63071e609747e6b9ad86969bb76ed3", preview_id = "dc63071e609747e6b9ad86969bb76ed3" }
    ]
    

    Change the id to the one you copied earlier. Save the file. Now, you're done!

    You could run the following command to serve the project locally:

    wrangler dev

    Or run the following command to publish it to your own subdomain:

    wrangler publish

License

Copyright for portions of project kv are held by [Github Account ashley williams Owner, 2018] as part of project worker-template.

All other copyright for project kv are held by [Github Account whinee Owner, 2022].

Check the LICENSE for more details.

Credits

MIT Logo

Massachusetts Institute of Technology (vectorized by Mysid, modified by whinee), Public domain, via Wikimedia Commons

Icons

Exclamation Mark, Code Fork, Star, Group, Code, and Discord icons by Icons8

NOTE: If a reference or source material is not attributed properly or not at all, please kindly message me at Discord: whi_ne#5135 or create a pull request so I can properly give credit to their respective authors.

About

Cloudflare KV Rest API (???)


Languages

Language:JavaScript 79.9%Language:Python 20.1%