---
title: "How to Build a CRUD API with Oak and Deno KV"
description: "Deno KV, a key-value database built into the Deno runtime, can back a simple CRUD API for users and addresses served by Oak's Router."
url: "https://swe.quest/articles/how-to-build-a-crud-api-with-oak-and-deno-kv-91b6dbad01b74ff7"
canonical: "https://deno.com/blog/build-crud-api-oak-denokv"
source: "Deno"
published: "2023-06-01"
difficulty: "medium"
kind: "How-to"
reading_minutes: 9
tags: ["typescript","databases","api-design","consistency"]
---

# How to Build a CRUD API with Oak and Deno KV

A post on [Deno](https://swe.quest/sources/deno.md), published 2023-06-01, 9 min read, How-to. Original: [https://deno.com/blog/build-crud-api-oak-denokv](https://deno.com/blog/build-crud-api-oak-denokv)

## Summary

Deno KV, a key-value database built into the Deno runtime, can back a simple CRUD API for users and addresses served by Oak's Router. The walkthrough models a secondary index on email as a separate key prefix that maps email to user ID. It uses kv.atomic() with .check() to keep the primary and index keys consistent under concurrent writes, and paginates kv.list() with limit and cursor. The code runs with the --unstable flag in Deno 1.33+ and is tested with curl.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)
- [Consistency models](https://swe.quest/tags/consistency.md) (Distributed systems)

## Prerequisites

- TypeScript basics ([easy posts on TypeScript](https://swe.quest/tags/typescript.md?difficulty=easy))
- REST API concepts ([easy posts on API design](https://swe.quest/tags/api-design.md?difficulty=easy))
- key-value stores

## Keywords

Deno KV, Deno, Oak, Deno Deploy

## Related posts

- [Announcing Deno KV](https://swe.quest/articles/announcing-deno-kv-d97d28c9a7128cf3.md): Deno · 2023-05-01 · Medium · 5 min read · Databases, Consistency models, Replication, JavaScript
  Deno KV is a strongly consistent key-value database built into the Deno runtime.
- [Use Deno KV in Node with the new official npm package](https://swe.quest/articles/use-deno-kv-in-node-with-the-new-official-npm-package-b89917dc2e71fbde.md): Deno · 2023-12-12 · Medium · 4 min read · JavaScript, Databases, Serverless
  Deno KV is now usable from Node.js through the official @deno/kv npm package, which exposes the same API as Deno's built-in KV through a single openKv function.
- [Introducing KV Backup for Deno Subhosting](https://swe.quest/articles/introducing-kv-backup-for-deno-subhosting-6886c3813b5bf7c0.md): Deno · 2024-07-09 · Medium · 4 min read · Serverless, Databases, JavaScript, Cloud platforms
  Deno Subhosting now supports continuous backup of Deno KV databases to customer-owned S3-compatible object storage, enabling point-in-time recovery.
- [Deno 1.33: Deno 2 is coming](https://swe.quest/articles/deno-1-33-deno-2-is-coming-2b1565b87f38fa7f.md): Deno · 2023-04-28 · Medium · 8 min read · JavaScript, Runtimes & VMs, TypeScript
  Deno 1.33 ships a built-in, unstable KV database (Deno.openKv) that persists to disk locally and is geo-replicated on Deno Deploy.
- [Announcing self-hosted Deno KV, continuous backups, and replicas](https://swe.quest/articles/announcing-self-hosted-deno-kv-continuous-backups-and-replicas-81eccdaa35f080ea.md): Deno · 2023-11-10 · Medium · 6 min read · Databases, SQLite, Replication, JavaScript
  Deno KV can now be self-hosted via an open-source, MIT-licensed \`denokv\` binary backed by SQLite and reachable from \`Deno.openKv\` over KV Connect.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
