Use this helper library to interact with the Pantry JSON storage API. The documentation for the Pantry API can be found here.
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')
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))
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))
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))
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))
const pantry = require('pantry-node')
const pantryID = "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx"
const pantryClient = new pantry(pantryID)
const link = pantryClient.basket.link('ToDoList')
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))