Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dario-piotrowicz/nitro-kv-exercise
https://github.com/dario-piotrowicz/nitro-kv-exercise
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dario-piotrowicz/nitro-kv-exercise
- Owner: dario-piotrowicz
- Created: 2024-04-08T18:12:51.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-04-16T16:39:50.000Z (7 months ago)
- Last Synced: 2024-05-13T17:22:56.218Z (6 months ago)
- Language: TypeScript
- Size: 61.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Create a CRD endpoint using Nitro
Using [Nitro](https://nitro.unjs.io/) (alongside one of its [Cloudflare presets](https://nitro.unjs.io/deploy/providers/cloudflare)) create a CRD (CRUD without the Update) endpoint that uses a [Cloudflare KV](https://developers.cloudflare.com/kv/)
to create, read and delete values.__GET__ requests to `/kv/` should return a result such as:
```ts
{
success: boolean,
value: string,
}
```where `success` indicate the success of the retrieval and `value` is the value of the entry (associated to the `KEY` key).
> Note: a value for the `CFLARE` key is already present in the local KV store
__PUT__ requests (with a `text/plain` `content-type` header) to `/kv/` should return a result such as:
```ts
{
success: boolean,
}
```
and __DELETE__ requests should do the same.## Test
To validate your progress you can start the nitro dev server in a terminal and in a separate terminal run `npm run test`
## You can use cURL to manually test the endpoint
To get a value for a key (note: a value for the `CFLARE` key is already present in the local KV) run:
```
curl localhost:3000/kv/
```to put a value for a key run:
```
curl -X PUT localhost:3000/kv/ -H "Content-Type: text/plain" --data 'test'
```and to delete the value of a key:
```
curl -X DELETE localhost:3000/kv/
```