Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -269,6 +285,13 @@ curl -X POST http://localhost:3000/db/docstore/put -H "Content-Type: application
zdpuAkkFaimxyRE2bsiLRSiybkku3oDi4vFHqPZh29BABZtZU
```

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:3000/db/keyvalue/put -H "Content-Type: application/json" -d '{"key":"Key","value":{ "name": "Value" }}'
```

### POST|PUT /db/:dbname/inc

Increments the counter database :dbname by 1.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"express": "^4.16.4",
"ipfs": "^0.34.4",
"ipfs-http-client": "^30.0.0",
"orbit-db": "0.20.0-rc.1"
"orbit-db": "0.20.0-rc.1.1"
}
}
15 changes: 14 additions & 1 deletion src/lib/orbitdb-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ class OrbitdbAPI extends Express {
var db_put = asyncMiddleware( async (req, res, next) => {
let db, hash
db = await dbm.get(req.params.dbname)
hash = await db.put(req.body)

if (db.type == 'keyvalue') {
let params = req.body;
hash = await db.put(params.key, params.value)
} else {
hash = await db.put(req.body)
}

return res.json(hash)
});

Expand Down Expand Up @@ -153,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)
Expand Down