Getting started
We will rely on what's known as Password Based Encryption concept. You (or your users) provide a "secret", which will then be used to generate and manage API tokens as well as cover all data hashing and encryption needs. The "secret", i.e. like login credentials, never gets sent to the server and never leaves the client side.
Include PrefsDB
First, include prefsdb client in your project
But before any read or write operations take place, your page must retrieve the API key/token.Get API token
Any read or write operation requires a valid API token (a.k.a. API Key).
prefs_us.getkey( keyId , seed_array [, options])
prefs_us.createkey( keyId , seed_array [, options])
Both function require two parameters (keyid and seed array) and accept an optional "Options" structure:
| parameter | type | description |
|---|---|---|
| keyId | string | Token ID or name, a plain string identifying the API token |
| seed | [ ] | Seed phrase array, an array of strings containing seed which will be utilized to built the token |
| options | { } | /optional/ Additional parameters to override default behavior (i.e. request timeuts etc) |
These two functions perform the same function: create and return an API key. The only difference is in how they handle a scenario where an existing key is already there.
getkey(): The function will either create a new key or return an existing one.
createkey(): The function will generate and return a new key - if one does not exist. If a key already exists this method will return a failure response.
Which method to use depends solely on your use case and the needs of your app.
Once you have a token, you are ready to read and write data.
Store data
Store large data
Read data
prefs_us.key("dataKey").read( (reply)=>{
let mydata = reply.value
// do something with your data
});
Notes
-
You may keep and re-use the same key for all subsequent queries to keep your items grouped together, whether saving or retrieving them.
-
Use grouping parameters such as 'project', 'domain', 'subdomain', or 'list' to help with organizing your data attached to your API key.
-
Create as many keys as you need but traffic may be a subject to rate limiting.
-
All timestamps are UTC