mhart / api-and-kv-example

Example code showing API and KV usage for Workers data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

api-and-kv-example

Example application used in the Workers 201 video course, "Managing Data in your Workers Application".

Usage

This example application shows how to set up an endpoint that requests data from GitHub. It transparently caches that data using KV.

  1. GET /repos/:username: get the repo data from GitHub for a given username, and return it as JSON.

Configuration

  1. Create a new KV namespace:
$ npx wrangler kv:namespace create api-and-kv-example
  1. Add the configuration details to your wrangler.toml file:
[[kv_namespaces]]
binding = "KV"
id = "your-kv-namespace-id"
  1. Deploy your application:
$ npx wrangler deploy
  1. Make a request to your Worker:
$ http https://worker-url.dev/repos/cloudflare

The initial request will take a few seconds to complete, but subsequent requests should be faster as the data is cached in KV.

About

Example code showing API and KV usage for Workers data


Languages

Language:TypeScript 100.0%