diff --git a/README.md b/README.md index bcfb9e7..838a147 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,22 @@ curl -X GET http://localhost:3000/db/feed/iterator -d 'limit=-1' See [OrbitDB's Iterator API](https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions-1) for more information. +### GET /db/:dbname/all + +Gets all items from a keyvalue database :dbname. + +Returns all items from a keyvalue store as a JSON object. + +Can only be used on keyvalue. + +```shell +curl -X GET http://localhost:3000/db/all +``` + +```json +{"Key1":{"name":"Value1"},"Key2":{"name":"Value2"},"projects":"{["orbitdb","ipfs"]}} +``` + ### POST|PUT /db/:dbname/add Adds a new entry to the eventlog or feed database :dbname. @@ -273,7 +289,7 @@ For the keyvalue store, a JSON object containing the variables `key` and `value` must be passed in the POST data: ```shell -curl -X POST http://localhost:3001/db/keyvalue/put -H "Content-Type: application/json" -d '{"key":"Key","value":{ "name": "Value" }}' +curl -X POST http://localhost:3000/db/keyvalue/put -H "Content-Type: application/json" -d '{"key":"Key","value":{ "name": "Value" }}' ``` ### POST|PUT /db/:dbname/inc diff --git a/src/lib/orbitdb-api.js b/src/lib/orbitdb-api.js index 55c60d0..4ffc3a7 100644 --- a/src/lib/orbitdb-api.js +++ b/src/lib/orbitdb-api.js @@ -160,6 +160,12 @@ class OrbitdbAPI extends Express { return res.json(contents) })); + this.get('/db/:dbname/all', asyncMiddleware( async (req, res, next) => { + let db + db = await dbm.get(req.params.dbname) + return res.json(db.all()) + })); + this.get('/db/:dbname/value', asyncMiddleware( async (req, res, next) => { let db, val db = await dbm.get(req.params.dbname)