Sheet Backend Generator
Turn any Google Sheet into a fully functional, free REST API. Generate the Apps Script to use your spreadsheet as a database.
How to setup:
- 1
Create a new Google Sheet and add your column headers (e.g. name, email) in the first row.
- 2
Click on Extensions > Apps Script in the menu.
- 3
Delete any existing code and paste the Apps Script Code shown here.
- 4
Click Deploy > New deployment. Select the gear icon and check Web app.
- 5
Set Execute as: Me and Who has access: Anyone. Click Deploy.
- 6
Copy the provided Web app URL. You will use this to make your API requests.
1. Apps Script Code (Code.gs)
function doPost(e) {
try {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = JSON.parse(e.postData.contents);
var headers = sheet.getRange(1, 1, 1, Math.max(1, sheet.getLastColumn())).getValues()[0];
var row = [];
for (var i = 0; i < headers.length; i++) {
var header = headers[i];
if (header) {
row.push(data[header] !== undefined ? data[header] : "");
}
}
if (row.length === 0) {
// If no headers, just append values in order
sheet.appendRow(Object.values(data));
} else {
sheet.appendRow(row);
}
return ContentService.createTextOutput(JSON.stringify({"success": true, "message": "Row added"}))
.setMimeType(ContentService.MimeType.JSON);
} catch (err) {
return ContentService.createTextOutput(JSON.stringify({"success": false, "error": err.toString()}))
.setMimeType(ContentService.MimeType.JSON);
}
}
function doGet(e) {
try {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = sheet.getDataRange().getValues();
if (data.length <= 1) {
return ContentService.createTextOutput(JSON.stringify({"success": true, "data": []}))
.setMimeType(ContentService.MimeType.JSON);
}
var headers = data[0];
var result = [];
for (var i = 1; i < data.length; i++) {
var obj = {};
for (var j = 0; j < headers.length; j++) {
if(headers[j]) {
obj[headers[j]] = data[i][j];
}
}
result.push(obj);
}
return ContentService.createTextOutput(JSON.stringify({"success": true, "data": result}))
.setMimeType(ContentService.MimeType.JSON);
} catch (err) {
return ContentService.createTextOutput(JSON.stringify({"success": false, "error": err.toString()}))
.setMimeType(ContentService.MimeType.JSON);
}
} 2. Client Fetch Example
// Example POST request to add a row
async function addRow(data) {
const url = 'YOUR_WEB_APP_URL';
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'text/plain;charset=utf-8',
}
});
const result = await response.json();
console.log(result);
}
// Make sure your sheet has headers like "name", "email", "message" in Row 1
addRow({ name: "John Doe", email: "john@example.com", message: "Hello!" });
// Example GET request to fetch all rows
async function getRows() {
const url = 'YOUR_WEB_APP_URL';
const response = await fetch(url);
const result = await response.json();
console.log(result.data);
} Benefits of Using Sheet Backend Generator
Completely Free
Avoid paying for external database hosting. Google Sheets and Apps Script provide generous free tiers perfect for small projects.
Zero Setup
No need to provision servers, configure SQL tables, or manage database credentials. Just paste the script and deploy.
REST API Ready
Generates standard GET and POST endpoints that you can fetch from any web application or mobile app.
Easy Management
View, edit, and delete your database records using the familiar Google Sheets interface instead of complex admin panels.
How to Use This Tool
Prepare Sheet
Create a new Google Sheet. In row 1, add your database column names (e.g., "id", "name", "email").
Add Script
In the Sheet menu, click Extensions > Apps Script. Delete any existing code and paste the generated script.
Deploy API
Click Deploy > New deployment. Select "Web app", set access to "Anyone", and authorize the permissions.
Fetch Data
Copy the provided Web App URL. Use standard fetch() in your JavaScript to GET rows or POST new data.
Common Use Cases
Contact Forms
Save website contact form submissions directly to a spreadsheet without needing a backend server.
Prototyping
Quickly spin up a working backend API for a hackathon project or MVP in less than 2 minutes.
Waitlists
Collect email addresses for an upcoming product launch and easily export the list later.
Related Guides
Comparisons
Popular Tools
QR Generator
Generate QR codes from URLs, text, and messages instantly.
Password Generator
Generate strong, secure passwords with custom length and options.
Hashtag Generator
Generate trending hashtags for social media posts and content.
JPG to PNG
Convert JPG images to PNG format with high quality preservation.
New Tools
Recently Used Tools
QR Generator
Generate QR codes from URLs, text, and messages instantly.
Password Generator
Generate strong, secure passwords with custom length and options.
Hashtag Generator
Generate trending hashtags for social media posts and content.
JPG to PNG
Convert JPG images to PNG format with high quality preservation.