localmockdb
v1.0.6
Published
Zero-setup mock REST API with localStorage / IndexedDB persistence for frontend development
Maintainers
Readme
localmockdb
Zero-setup mock REST API for frontend development
Persist data using localStorage / IndexedDB — survives page reloads.
No backend. No config. Just install and start building.
🔗 Live Demo
👉 https://shrikant9907.github.io/localmockdb-demo/
Try the full CRUD flow in your browser — no setup required.
🚀 Why localmockdb?
Waiting for backend APIs slows you down.
With localmockdb, you can:
👉 Build and test UI independently
👉 Simulate real REST APIs (GET, POST, PUT, PATCH, DELETE)
👉 Persist data automatically (no manual state handling)
👉 Ship demos and prototypes faster
💡 What makes it simple for frontend projects?
localmockdb is designed for frontend-first development.
👉 No setup, no config
Just install and start using. No JSON files, no servers, no environment setup.
👉 API feels real
Use familiar REST methods like get, post, patch, delete.
👉 No state management needed
Data is automatically stored and persisted.
👉 Auto everything
IDs, timestamps, and responses are handled internally.
👉 Works directly inside components
No need for complex API layers.
👉 Safe for rapid iteration
Reset, test, rebuild — no backend dependency.
👉 Drop-in replace later
Easily switch to real APIs when backend is ready.
✨ Features
| Feature | Details |
|--------|--------|
| Persistence | localStorage (default) or IndexedDB |
| Full CRUD | GET, POST, PUT, PATCH, DELETE |
| API-like responses | statusCode, success, data, error, meta |
| Method validation | Returns 405 for invalid methods |
| Pagination | Supports ?page= and ?limit= |
| Auto timestamps | createdAt, updatedAt |
| Auto IDs | UUID generated automatically |
| Namespacing | Multiple DB instances supported |
| Zero dependencies | Pure TypeScript |
📦 Installation
npm
npm install localmockdbpnpm
pnpm add localmockdbyarn
yarn add localmockdb⚡ Quick Start
import { createAPI } from "localmockdb";
const db = createAPI();
await db.post("/users", { name: "Shrikant" });
await db.get("/users");
await db.get("/users/1");
await db.patch("/users/1", { name: "Updated" });
await db.delete("/users/1");Data is automatically persisted.
⚛️ React / Next.js Example
// lib/db.ts
import { createAPI } from "localmockdb";
export const db = createAPI();import { useEffect, useState } from "react";
import { db } from "./lib/db";
export default function Users() {
const [users, setUsers] = useState([]);
useEffect(() => {
loadUsers();
}, []);
async function loadUsers() {
const res = await db.get("/users");
if (!res.success) return;
setUsers(res.data);
}
async function addUser() {
await db.post("/users", { name: "New User" });
loadUsers();
}
return (
<div>
<button onClick={addUser}>Add User</button>
{users.map((user: any) => (
<div key={user.id}>{user.name}</div>
))}
</div>
);
}📡 Example Response
{
"success": true,
"statusCode": 200,
"data": [
{
"id": "uuid",
"name": "Shrikant",
"createdAt": "2026-04-21T10:00:00.000Z",
"updatedAt": "2026-04-21T10:00:00.000Z"
}
]
}🔄 Reset Database
await db.reset();🎯 Use Cases
- Frontend development without backend
- Rapid prototyping
- Learning React / Next.js
- UI testing
⚠️ Not for Production
- Not a real backend
- Not for large-scale systems
📝 Notes
- Uses localStorage by default
- Data persists after refresh
- Can be cleared manually
📄 License
MIT
