Save data
Endpoint: /write
Supported HTTP methods: Get, Post
HTTP GET
Data can be saved with a basic HTTP Get by listing key/value pairs as URL parameters.
Note
Basic key/value pairs are mutable. Meaning that if a key already exists, its value will be modified with a new value. To collect duplicate values of the same key use: Lists.
HTTP POST
Using GET method with /write endpoint is fairly straightforward and simple but it has its limitations. There are hard limits on how much data can be sent via HTTP GET. Larger blobs of data can be saved using the .post() method.
NOTE: blobId (URL parameter with no value) is optional, but if specified, it allows to retrieve individual items.
Prefs.us Libs
Include prefs.us Javascript library in your project:
Retrieve your API Key and collect data to be saved:
const apikey = prefs_us.getkey("keyid", "secret");
const data = "... large chunk of data ...";
prefs_us.using("apikey").post(data);
Store data under a project and a domain named my-project and test-domain for 10 days. An optional callback was added to check the result of write operation.
import prefus as prefs
String data = "base64abcd...";
prefs.using("apikey...");
#
# Python comments space filler.
# TODO: prefs.us integrations for all major server side tech like fastAPI?
#
prefs.ttl(10) # store for 10 days only
.project("my-project") # grouping
.domain("test-domain") # grouping
.for("JohnDoe") # data chunk identifier
.post(data); # use HTTP POST
The piece of data save above can be retrieved using the sample code below: