Farwalker3 | Rogues
Farwalker3 | Rogues
CDCloudflare Developers
Created by Farwalker3 | Rogues on 4/1/2024 in #workers-help
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 []; } }
5 replies