Get Started in Seconds
1. Store Data (POST)
POST https://litedb.code/db
// Request Body
{
"id": "example-db-wieuh-345",
"name": "Alok",
"city": "Chennai"
}
2. Retrieve Data (GET)
GET https://litedb.code/db?id=example-db-wieuh-345
// Response
{
"id": "example-db-wieuh-345",
"name": "Alok",
"city": "Chennai"
}
JavaScript Example
const dbId = 'example-db-wieuh-345'
const url = `https://litedb.code/db?id=${dbId}`
// Store data
await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: 'example-db-wieuh-345', name: 'Alok', city: 'Chennai' })
})
// Retrieve data
const response = await fetch(url)
const data = await response.json()
HTML Form Submission
<!-- HTML -->
<form id="userForm">
<input type="text" id="name" placeholder="Enter name" />
<input type="text" id="city" placeholder="Enter city" />
<button type="submit">Save Data</button>
</form>
<!-- JavaScript -->
<script>
document.getElementById('userForm').addEventListener('submit', async (e) => {
e.preventDefault()
const name = document.getElementById('name').value
const city = document.getElementById('city').value
await fetch('https://litedb.code/db', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: 'example-db-wieuh-345', name, city })
})
alert('Data saved!')
})
</script>
Display Data on Webpage
<!-- HTML -->
<div id="userData">Loading...</div>
<button onclick="loadData()">Load Data</button>
<!-- JavaScript -->
<script>
async function loadData() {
try {
const response = await fetch('https://litedb.code/db?id=example-db-wieuh-345')
const data = await response.json()
const userDiv = document.getElementById('userData')
userDiv.innerHTML = `
<h3>User Information</h3>
<p><strong>Name:</strong> ${data.name}</p>
<p><strong>City:</strong> ${data.city}</p>
`
} catch (error) {
document.getElementById('userData').innerHTML = 'Error loading data'
}
}
// Load data when page loads
loadData()
</script>