rocicorp / replicache-echo-backend

The simplest possible Replicache backend - integrates Replicache with an array :).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replicache Echo Backend

This is maybe the simplest possible example of a Replicache backend.

It's completely in-memory. All state will be lost when it exits.

To learn more about the Replicache protocol, and how to connect to your own backend, see Replicache Server Setup.

For a more real-life example of a backend integration, see replicache-sample-todo.

Setup

npm install

Run

node .

Your Replicache endpoints are:

  • http://localhost:3001/replicache-client-view
  • http://localhost:3001/replicache-batch

Example Usage

curl -X POST -d '{"clientID":"1", "mutations":[{"id":1,"name":"foo","args":"42"}]}' -H "Content-type: application/json" http://localhost:3001/replicache-batch
curl -X POST -d '{"clientID":"1", "mutations":[{"id":2,"name":"bar","args":"true"}]}' -H "Content-type: application/json" http://localhost:3001/replicache-batch

curl -X POST -d '{"clientID":"1"}' -H "Content-type: application/json" http://localhost:3001/replicache-client-view

Outputs:

% node .              
Example app listening at http://localhost:3001
> /replicache-batch { clientID: '1', mutations: [ { id: 1, name: 'foo', args: '42' } ] }
< /replicache-batch
> /replicache-batch { clientID: '1', mutations: [ { id: 2, name: 'foo', args: 'true' } ] }
< /replicache-batch
/replicache-client-view { clientID: '1' }
/replicache-client-view {
  lastMutationID: 2,
  clientView: {
    init: 'hello world',
    'm/0': { id: 1, name: 'foo', args: '42' },
    'm/1': { id: 2, name: 'foo', args: 'true' }
  }
}

About

The simplest possible Replicache backend - integrates Replicache with an array :).

License:MIT License


Languages

Language:JavaScript 100.0%