LoginSignup
1
0

More than 1 year has passed since last update.

Deno KVでMyJSON【JSON保管庫】

Posted at

See the Pen MyJSON Deno KV by John Doe (@04) on CodePen.

http://myjson.com の代替え品を作りました!

import { serve } from "https://deno.land/std@0.177.0/http/server.ts"

const kv = await Deno.openKv()

serve(async (req: Request) => {
    const key = new URL(req.url).pathname.slice(1)
    if (req.method === "GET") {
        const { value } = await kv.get([ key ])
        const init = {
            headers: {
                "content-type": "application/json; charset=UTF-8",
                "Access-Control-Allow-Origin": "*"
            }
        }
        return new Response(value, init)
    } else if (req.method === "POST") {
        kv.set([ key ], await req.text())
    }
    return new Response('', { headers: { "Access-Control-Allow-Origin": "*" } })
})

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0