Skip to content

Turn any browser tab into a REST API server. Zero backend needed.

License

Notifications You must be signed in to change notification settings

Tryboy869/api-in-browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

gitsearch gitsearch-tags

API in Browser

API in Browser

Turn any browser tab into a REST API server. Zero backend needed.

npm version npm downloads GitHub stars License Build Status Bundle Size TypeScript

Demo Animation

πŸ“¦ Install β€’ πŸ“– Docs β€’ 🎯 Examples β€’ πŸ’¬ Community


🎯 What This Is

import API from 'api-in-browser';

const api = new API();

api.get('/hello', (req, res) => {
  res.json({ message: 'Hello from your browser!' });
});

api.listen(); // API running β€” no server needed

A framework that transforms your browser into a fully functional REST API server using:

Feature Technology
πŸ”„ Request Handling Polling / Service Workers
πŸ’Ύ Storage IndexedDB (60GB+)
πŸ”— Cross-Tab postMessage API
⚑ Concurrency Web Workers

Perfect for:

  • πŸ€– Telegram bots running in a browser tab
  • πŸ’Ό Local-first apps with zero backend cost
  • πŸ§ͺ Prototyping APIs without servers
  • 🌐 P2P applications
  • ⚑ Edge computing experiments

πŸš€ Quick Start

Installation

npm install api-in-browser

Or via CDN:

<script type="module">
  import API from 'https://cdn.jsdelivr.net/npm/api-in-browser/src/index.js';
</script>

Your First API (30 seconds)

import API from 'api-in-browser';

const api = new API({
  polling: true,
  pollingInterval: 2000
});

api.get('/users', async (req, res) => {
  const users = await api.storage.getAll('users');
  res.json(users);
});

api.post('/users', async (req, res) => {
  const user = req.body;
  await api.storage.set('users', user.id, user);
  res.json({ success: true, user });
});

api.listen(() => console.log('πŸš€ API running in browser'));

✨ Features

🎯 REST API in Browser

  • GET, POST, PUT, DELETE, PATCH
  • Query parameters & body parsing
  • Response helpers: json(), text(), setStatus()

πŸ’Ύ Built-in Storage

  • IndexedDB wrapper with dead-simple API
  • 60GB+ quota (Chrome/Firefox)
  • Persistent across sessions β€” no setup

πŸ€– Telegram Bot Support

  • Long-polling built-in β€” no webhook server needed
  • Message queue management
  • Handler-based routing (/start, /help, etc.)

πŸ”— Cross-Tab Communication

  • Broadcast updates via postMessage
  • Shared state between tabs
  • Event synchronization

πŸ’‘ Examples

1️⃣ Simple Counter API

import API from 'api-in-browser';

const api = new API();
let counter = 0;

api.get('/counter', (req, res) => {
  res.json({ count: counter });
});

api.post('/counter/increment', (req, res) => {
  counter++;
  res.json({ count: counter });
});

api.listen();

2️⃣ Telegram Bot

import API from 'api-in-browser';

const api = new API({ polling: true, pollingInterval: 2000 });

api.telegramBot('YOUR_BOT_TOKEN', {
  '/start': (msg) => `Hello ${msg.from.first_name}!`,
  '/help':  () => 'Commands: /start, /help, /ping',
  '/ping':  () => 'Pong! πŸ“'
});

api.listen();

3️⃣ Todo List with Storage

import API from 'api-in-browser';

const api = new API();

api.get('/todos', async (req, res) => {
  res.json(await api.storage.getAll('todos'));
});

api.post('/todos', async (req, res) => {
  const todo = { id: Date.now(), ...req.body };
  await api.storage.set('todos', todo.id, todo);
  res.json(todo);
});

api.delete('/todos/:id', async (req, res) => {
  await api.storage.delete('todos', req.params.id);
  res.json({ success: true });
});

api.listen();

πŸ“‚ More Examples


⚠️ Limitations

Aspect Reality Use Case
Uptime Runs while tab is open βœ… Personal tools
Concurrency ~10-50 req/sec βœ… Small groups
Storage 60GB (Chrome/Firefox) βœ… Local-first
Mobile May pause in background ⚠️ Desktop recommended
Security Your IP = API IP βœ… Private use

Perfect for: Personal bots, MVPs, local-first apps, P2P experiments.

Not suitable for: Production high-traffic APIs, apps requiring 24/7 uptime.


πŸ“– API Reference

Initialization

const api = new API(options);

Options:

Option Type Default Description
polling boolean false Enable polling mode
pollingInterval number 2000 Polling frequency (ms)
cors boolean true Enable CORS headers
storage string 'indexeddb' Storage backend
debug boolean false Debug logging

Routes

api.get(path, handler)
api.post(path, handler)
api.put(path, handler)
api.delete(path, handler)
api.patch(path, handler)

Handler: (req, res) => { } where:

  • req: { method, path, params, query, body }
  • res: { json(), text(), setStatus() }

Storage

await api.storage.set(store, key, value)
await api.storage.get(store, key)
await api.storage.getAll(store)
await api.storage.delete(store, key)
await api.storage.clear(store)

πŸ“š Full API Documentation


🌟 Philosophy

"The browser is the most distributed computer on Earth. Let's use it."

This framework embraces Informatique RΓ©alitaire (Reality Computing) β€” building systems that work with physical constraints rather than against them.

No pretense of being a server. It's a browser that behaves like a server when needed.


πŸ‘¨β€πŸ’» Author

Daouda Abdoul Anzize

Daouda Abdoul Anzize β€” Computational Paradigm Designer

"I don't build apps. I build the clay others use to build apps."

24 ans β€’ Cotonou, BΓ©nin β†’ Global Remote

What I Create:

  • Meta-Architectures β†’ Systems that absorb multiple programming paradigms
  • Universal Protocols β†’ Standards for distributed systems reliability
  • Emergent Computing β†’ Solutions arising from simple physical laws
  • AI Infrastructure β†’ Collective intelligence platforms

Featured Research:

  • NEXUS AXION β€” Universal computational framework
  • Nexus Backpressure Protocol β€” 60%+ latency reduction in distributed systems
  • Informatique RΓ©alitaire (IR) β€” Framework for artificial cognition
  • Weak Hardware Booster β€” 95% CPU reduction via semantic collision convergence
  • API in Browser β€” REST API server running inside a browser tab

Stack: Python Β· Rust Β· C++ Β· JavaScript Β· Go

Email Portfolio Twitter

🎯 Seeking: Research engineering · AI infrastructure · Protocol design (Q1 2026)


πŸ“„ License

MIT Β© 2026 Daouda Abdoul Anzize β€” Use freely, attribution appreciated.


πŸ™ Acknowledgments

Inspired by the Local-First movement, CRDTs, Service Workers, and IndexedDB as underrated infrastructure.

Built with the philosophy that constraints breed creativity.


GitHub npm

Made with ❀️ by Nexus Studio

Proof that creativity transcends credentials

About

Turn any browser tab into a REST API server. Zero backend needed.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors