Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 907e4d1

Browse files
Hayden Youngphillmac
authored andcommitted
Support key/value pairs for keyvalue store. (#4)
* Support key/value pairs for keyvalue store. * Additional docs for POSTing key/value pairs.
1 parent 6b68013 commit 907e4d1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ curl -X POST http://localhost:3000/db/docstore/put -H "Content-Type: application
269269
zdpuAkkFaimxyRE2bsiLRSiybkku3oDi4vFHqPZh29BABZtZU
270270
```
271271

272+
For the keyvalue store, a JSON object containing the variables `key` and
273+
`value` must be passed in the POST data:
274+
275+
```shell
276+
curl -X POST http://localhost:3001/db/keyvalue/put -H "Content-Type: application/json" -d '{"key":"Key","value":{ "name": "Value" }}'
277+
```
278+
272279
### POST|PUT /db/:dbname/inc
273280

274281
Increments the counter database :dbname by 1.

src/lib/orbitdb-api.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ class OrbitdbAPI extends Express {
6666
var db_put = asyncMiddleware( async (req, res, next) => {
6767
let db, hash
6868
db = await dbm.get(req.params.dbname)
69-
hash = await db.put(req.body)
69+
70+
if (db.type == 'keyvalue') {
71+
let params = req.body;
72+
hash = await db.put(params.key, params.value)
73+
} else {
74+
hash = await db.put(req.body)
75+
}
76+
7077
return res.json(hash)
7178
});
7279

0 commit comments

Comments
 (0)