pantry-node
v0.1.3
Published
A convenient wrapper to access the Pantry storage API
Downloads
22
Maintainers
Readme
pantry-node
Use this helper library to interact with the Pantry JSON storage API. The documentation for the Pantry API can be found here.
Installation
The easiest way to install pantry-node is from NPM. You can run the command below from your project directory to install the library:
npm install pantry-node
Then in your code:
const pantry = require('pantry-node')
Testing your Installation
Try creating a new basket in your pantry, like this:
const pantry = require('pantry-node')
const pantryID = "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx" // Your unique PantryID
const pantryClient = new pantry(pantryID)
// The payload that you want your basket to have
const payload = {
pending: [],
complete: []
}
pantryClient.basket
.create('ToDoList', payload)
.then((response) => console.log(response))
Modifying Baskets
Retrieve Basket Contents
const pantry = require('pantry-node')
const pantryID = "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx"
const pantryClient = new pantry(pantryID)
const options = { parseJSON: true } // optional
pantryClient.basket
.get('ToDoList', options)
.then((contents) => console.log(contents))
Update Basket Contents
const pantry = require('pantry-node')
const pantryID = "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx"
const pantryClient = new pantry(pantryID)
const options = { parseJSON: true } // optional
// The new payload that you want your basket to have
const payload = {
pending: ["Walk the Dog"]
}
pantryClient.basket
.update('ToDoList', payload, options)
.then((response) => console.log(response))
Delete a Basket
const pantry = require('pantry-node')
const pantryID = "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx"
const pantryClient = new pantry(pantryID)
pantryClient.basket
.delete('ToDoList')
.then((response) => console.log(response))
Extras
Get the direct link to a basket
const pantry = require('pantry-node')
const pantryID = "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx"
const pantryClient = new pantry(pantryID)
const link = pantryClient.basket.link('ToDoList')
Retrieve Account Details
const pantry = require('pantry-node')
const pantryID = "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx"
const pantryClient = new pantry(pantryID)
pantryClient.details()
.then((response) => console.log(response))