© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•2y ago•
4 replies
Farwalker3 | Rogues

Fetching From D1 using Workers

How Do I Create an endpoint using Cloudflare D1 and workers that returns the entire table as JSON when fetched?

I want to know what code I need to put in the workers.js file to return the entire table from a D1 database as JSON when fetched.

I need this so that on an HTML page, I can fetch the JSON using the public read-only endpoint, and then I already have the rest of the code working, where it creates a array using the JSON.

In other words, I want to create a read-only D1 worker that will replace my current nocodb endpoint:

async function fetchAllData() {
try {
const response = await fetch('https://app.nocodb.com/api/v1/db/data/noco/phgforxa020gg7q/ml1ww2bojawn3mf/views/vwy72p5sijrhvnmg?where=(Public,eq,true)', options);
if (!response.ok) throw new Error('Failed to fetch data');
return (await response.json()).list;
} catch (error) {
console.error(error);
return [];
}
}
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Using --local with workers and D1
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
10mo ago
522 on fetching from CF workers
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3mo ago
Workers build with Next.js static generation using D1 database
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
5mo ago
Prisma with D1 NextJs and CF Workers
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
8mo ago