See the Pen Untitled by John Doe (@04) on CodePen.
import { serve } from "https://deno.land/std@0.177.0/http/server.ts";
const kv = await Deno.openKv()
serve(async (req: Request) => {
const id = new URL(req.url).pathname.slice(1)
if (req.method === 'GET') {
const { value } = await kv.get([id])
return value ? Response.redirect(value) : new Response('404 Not Found', { status: 404 })
} else if (req.method === 'POST') {
await kv.set([id], await req.text())
return new Response('201 Created', { status: 201 })
}
})
URLの更新手順
curl https://sht.deno.dev/abc -d https://deno.com/blog/kv
管理画面で確認できます