Skip to content

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.

https://prefs.us/write?key=...&key1=value1&key2=value2&...

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.

https://prefs.us/write?key=...&blobId
[post body]

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:

<script src="https://prefs.us/prefs.us.min.js"></script>

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.

const data = "base64abcd...";

prefs_us.using("apikey...");
prefs_us.ttl(10)                // store for 10 days only
        .project('my-project')  // grouping
        .domain('test-domain')  // grouping
        .for('JohnDoe')         // additional identifier
        .post(data);            // use HTTP POST  
import com.gorny.prefsus;

String data = "base64abcd...";
PrefsUs prefs = new PrefsUs("apikey...");

prefs.ttl(10)               // store for 10 days only
    .project("my-project")  // grouping
    .domain("test-domain")  // grouping
    .for("JohnDoe")         // additional identifier
    .post(data);            // use HTTP POST  
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:

JavaScript Read Example
prefs_us.project('my-project')
    .domain('test-domain')
    .find('JohnDoe')
    .read( (incoming) => {
        if (incoming.status == 'success') {
            var mydata = incoming.values;
        }
    });