PouchDB adapter using HTTP for remote CouchDB connections and database operations
npx @tessl/cli install tessl/npm-pouchdb-adapter-http@9.0.0PouchDB HTTP Adapter is a plugin that enables PouchDB to connect to remote CouchDB servers and HTTP-compatible databases. It provides a complete implementation of the PouchDB adapter interface for HTTP/HTTPS protocols, supporting both Node.js and browser environments with authentication, cookie management, and comprehensive database operations.
npm install pouchdb-adapter-http// Import PouchDB and the HTTP adapter
import PouchDB from 'pouchdb-core';
import HttpAdapter from 'pouchdb-adapter-http';
// Register the adapter
PouchDB.plugin(HttpAdapter);For CommonJS:
const PouchDB = require('pouchdb-core');
const HttpAdapter = require('pouchdb-adapter-http');
PouchDB.plugin(HttpAdapter);import PouchDB from 'pouchdb-core';
import HttpAdapter from 'pouchdb-adapter-http';
PouchDB.plugin(HttpAdapter);
// Connect to remote CouchDB
const db = new PouchDB('http://localhost:5984/mydb', {
auth: {
username: 'admin',
password: 'password'
}
});
// Basic document operations
const doc = await db.put({
_id: 'user:john',
name: 'John Doe',
email: 'john@example.com'
});
const retrieved = await db.get('user:john');
console.log(retrieved.name); // 'John Doe'The HTTP adapter implements the PouchDB adapter interface to provide:
fetch API with cookie support for all database operationsCore database management functionality including connection setup, database info retrieval, and lifecycle operations.
// Constructor for HTTP adapter
function HttpPouch(opts, callback);
// Database information
api._info(callback): void;
api.id(callback): void;
// Database lifecycle
api._destroy(options, callback): void;
api._close(callback): void;
api.compact(opts, callback): void;Complete CRUD operations for individual and bulk document management.
// Single document operations
api.get(id, opts, callback): void;
api._put(doc, opts, callback): void;
api.remove(docOrId, optsOrRev, opts, callback): void;
// Bulk operations
api._bulkDocs(req, opts, callback): void;
api.bulkGet(opts, callback): void;
api.allDocs(opts, callback): void;
api.revsDiff(req, opts, callback): void;File attachment management with support for binary data and proper content types.
// Attachment CRUD operations
api.getAttachment(docId, attachmentId, opts, callback): void;
api.putAttachment(docId, attachmentId, rev, blob, type, callback): void;
api.removeAttachment(docId, attachmentId, rev, callback): void;Real-time database changes streaming with filtering and continuous monitoring support.
// Changes feed with various options
api._changes(opts): { cancel: function };Low-level HTTP access and utility functions for custom requests.
// Direct HTTP access
api.fetch(path, options): Promise<Response>;
// Adapter validation
HttpPouch.valid(): boolean;// Constructor options
interface HttpPouchOptions {
name: string;
auth?: {
username: string;
password: string;
};
headers?: { [key: string]: string };
fetch?: Function;
skip_setup?: boolean;
}
// Common callback pattern
type PouchCallback<T> = (error: Error | null, result?: T) => void;
// Document structure
interface PouchDoc {
_id: string;
_rev?: string;
[key: string]: any;
}
// Database info response
interface DatabaseInfo {
db_name: string;
doc_count: number;
doc_del_count: number;
update_seq: string | number;
purge_seq: string | number;
compact_running: boolean;
disk_size: number;
data_size: number;
instance_start_time: string;
disk_format_version: number;
committed_update_seq: string | number;
host: string;
}