REST API
See root documentation of API References.
Helper Library
Can make a db.js
and can access common functions.
Copy
var request = require("request");
var accessKey = process.env.ACCESS_KEY;
var endpoint = "https://memory.backbench.io";
module.exports = {
"bbMemSet": function(key, value, cb){
request.post({
url: "https://memory.backbench.io",
body: {
"cmd": "bb:mem:set",
"auth": {
"benchId": "addressbookapp",
"userId": "peeyushsrj",
"accessKey": accessKey
},
"args": {
"key": key,
"value": value
}
},
json: true
}, function (error, response, body) {
if (error) {
cb(error);
} else{
cb(undefined, body);
}
});
},
"bbMemGet": function(key, cb){
request.post({
url: "https://memory.backbench.io",
body: {
"cmd": "bb:mem:get",
"auth": {
"benchId": "addressbookapp",
"userId": "peeyushsrj",
"accessKey": accessKey
},
"args": {
"key": key
}
},
json: true
}, function (error, response, body) {
if (error) {
cb(error);
} else{
cb(undefined, body.reply);
}
});
},
"bbLog": function(message, cb){
request.post({
url: "https://memory.backbench.io",
body: {
"cmd": "bb:log",
"auth": {
"benchId": "addressbookapp",
"userId": "peeyushsrj",
"accessKey": accessKey
},
"args": {
"message": message
}
},
json: true
}, function (error, response, body) {
if (error) {
cb(error);
} else{
cb(undefined, body.reply);
}
});
}
};
SDK
Available publicaly on https://www.npmjs.com/package/backbench-node-sdk .
NOTE : For local development you need to copy ACCESS_KEY
environment variable from platform and make it as local environment variable with same key. Also need to require backbench-node-sdk
for local.
Getting memory
Copy bb.memGet(key, function(err, res){})
Setting memory
Copy bb.memSet(key, value, function(err, res){})
Deleting memory
Copy bb.memDel(key, function(err, res){})
Logging
Copy bb.log(variable, variable2, ...)
Example
Copy exports.endpoint = function(req, cb){
let username = req.body.user || "constantine"
bb.memSet("user", username, function(err){
if(err){
bb.log(err)
cb("error_in_mem_set")
}
bb.memGet("user", funtion(err, data){
if(err) {
bb.log(err)
cb("error_in_mem_get");
}
cb(null, {data: data})
})
})
}
File Upload
You can upload your file with a regular enctype='multipart/form-datain
using POST
method your HTML form.
Copy <form method="POST" enctype='multipart/form-data' action="/imageSet">
<input type="file" name="upload" />
<input type="submit" name="submit" />
</form>
The file you have uploaded will be in base64
. That you can either convert to text or store it in database.
Here's the response body printed at backend.
Copy {
"method": "POST",
"path": "/form",
"body": {},
"headers": {
"host": "https://peeyushsrj-haunted.beta-bench.backbench.io",
"connection": "keep-alive",
"content-length": "4331",
"cache-control": "max-age=0",
"origin": "https://peeyushsrj-haunted.beta-bench.backbench.io",
"upgrade-insecure-requests": "1",
"content-type": "multipart/form-data; boundary=----WebKitFormBoundaryseiR2HWoPTT3iOod",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 OPR/55.0.2994.59",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"referer": "https://peeyushsrj-haunted.beta-bench.backbench.io/form.html",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9"
},
"query": {},
"file": {
"name": "login.html",
"path": "upload_8f3dc10ed6804e2839e9f26a37251b56",
"size": 103,
"type": "text/html",
"content": "PGEgaHJlZj0iaHR0cHM6Ly9naXRodWIuY29tL2xvZ2luL29hdXRoL2F1dGhvcml6ZT9jbGllbnRfaWQ9ZGU3ZGQ1NDM2ZjViZWQ5ZWQxODMiPkxvZ2luIHdpdGggR2l0aHViPC9hPg=="
}
}
And this is the code for printing it.
Copy exports.endpoint = function(req, cb){
cb(undefined, req);
}
Note : Currently supports only single file upload.