CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-pouchdb-adapter-http

PouchDB adapter using HTTP for remote CouchDB connections and database operations

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

PouchDB HTTP Adapter

PouchDB 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.

Package Information

  • Package Name: pouchdb-adapter-http
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install pouchdb-adapter-http

Core Imports

// 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);

Basic Usage

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'

Architecture

The HTTP adapter implements the PouchDB adapter interface to provide:

  • HTTP Communication: Uses fetch API with cookie support for all database operations
  • Authentication: Supports Basic Auth with automatic header management
  • Error Handling: Translates HTTP status codes to PouchDB-compatible errors
  • Adapter Registration: Registers both 'http' and 'https' adapter types with PouchDB
  • Browser/Node Compatibility: Works in both browser and Node.js environments

Capabilities

Database Operations

Core 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;

Database Operations

Document Operations

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;

Document Operations

Attachment Operations

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;

Attachment Operations

Changes Feed

Real-time database changes streaming with filtering and continuous monitoring support.

// Changes feed with various options
api._changes(opts): { cancel: function };

Changes Feed

HTTP Utilities

Low-level HTTP access and utility functions for custom requests.

// Direct HTTP access
api.fetch(path, options): Promise<Response>;

// Adapter validation
HttpPouch.valid(): boolean;

HTTP Utilities

Types

// 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;
}

Install with Tessl CLI

npx tessl i tessl/npm-pouchdb-adapter-http
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/pouchdb-adapter-http@9.0.x
Publish Source
CLI
Badge
tessl/npm-pouchdb-adapter-http badge