PouchDB HTTP Adapter

9.0.0 · active · verified Wed Apr 22

pouchdb-adapter-http is a PouchDB plugin that enables the core PouchDB library to use HTTP as its data store, allowing it to seamlessly communicate and synchronize with remote CouchDB or CouchDB-like databases. This adapter is crucial for applications requiring offline-first capabilities combined with cloud synchronization. Currently stable at version 9.0.0, PouchDB maintains a consistent release cadence with frequent patch updates and less frequent major/minor versions. Key differentiators include its ability to abstract away the complexities of HTTP requests and responses, providing a familiar PouchDB API for remote data operations, and its design for use in both Node.js and browser environments, making it a versatile component within the PouchDB ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and register the HTTP adapter, then connect to a remote CouchDB instance, add a document, and retrieve it.

import PouchDB from 'pouchdb';
import HttpPouch from 'pouchdb-adapter-http';

PouchDB.plugin(HttpPouch);

// Create a PouchDB instance that connects to a remote CouchDB via HTTP
const remoteDbUrl = process.env.COUCHDB_URL ?? 'http://127.0.0.1:5984/mydb';
const db = new PouchDB(remoteDbUrl);

async function runExample() {
  try {
    // Add a document
    const doc = {
      _id: 'mydoc-1',
      title: 'Hello PouchDB HTTP',
      description: 'This document is stored remotely.'
    };
    const response = await db.put(doc);
    console.log('Document added:', response);

    // Get the document
    const fetchedDoc = await db.get('mydoc-1');
    console.log('Document fetched:', fetchedDoc);

    // You can also listen to changes, replicate, etc.
    console.log(`PouchDB adapter in use: ${db.adapter}`);

  } catch (err) {
    console.error('Error:', err);
  }
}

runExample();

view raw JSON →