Strings API
Store and manipulate single string values with expiration, increment, and range operations
The Strings API stores single values per key. It is the simplest way to keep text, counters, tokens, feature flags, and cached serialized data.
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /{plateId}/strings/get/{key} | Get one value |
| POST | /{plateId}/strings/get | Get many values |
| POST | /{plateId}/strings/set | Set one value |
| POST | /{plateId}/strings/set-many | Set many values |
| POST | /{plateId}/strings/increment | Increment integer or float |
| POST | /{plateId}/strings/decrement | Decrement integer |
| POST | /{plateId}/strings/append | Append to a string |
| GET | /{plateId}/strings/length/{key} | Get string length |
| GET | /{plateId}/strings/range/{key} | Read a substring |
| POST | /{plateId}/strings/range/set | Replace part of a string |
| POST | /{plateId}/strings/get-and-expire | GETEX wrapper |
| DELETE | /{plateId}/strings/get-and-delete/{key} | GETDEL wrapper |
| POST | /{plateId}/strings/command | Execute allowed string commands |
| POST | /{plateId}/strings/{key}/command | Execute key-specific string commands |
Common Patterns
Store a Value
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/set`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "mykey",
value: "hello world"
})
});
const data = await response.json();
console.log(data);Store with Expiration
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/set`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "session:123",
value: "abc123",
ttl_ms: 3600000
})
});
const data = await response.json();
console.log(data);Conditional Set
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/set`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "lock:job:42",
value: "worker-1",
nx: true,
ttl_ms: 30000
})
});
const data = await response.json();
console.log(data);Get a Value
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/get/mykey`, {
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
}
});
const data = await response.json();
console.log(data);Get Multiple Values
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/get`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
keys: ["key1", "key2", "key3"]
})
});
const data = await response.json();
console.log(data);Set Multiple Values
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/set-many`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
values: {
key1: "value1",
key2: "value2"
}
})
});
const data = await response.json();
console.log(data);Increment Counters
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/increment`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "counter",
amount: 10
})
});
const data = await response.json();
console.log(data);Float increments are supported too:
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/increment`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "price",
amount: 1.5
})
});
const data = await response.json();
console.log(data);Decrement
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/decrement`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "counter",
amount: 5
})
});
const data = await response.json();
console.log(data);Append
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/append`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "greeting",
value: " world"
})
});
const data = await response.json();
console.log(data);Range Operations
Read a substring:
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/${plateId}/strings/range/greeting?start=0&end=4`, {
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
}
});
const data = await response.json();
console.log(data);Query parameters:
start(optional): Start index (default: 0)end(optional): End index (default: -1, meaning to the end)
Replace part of a string:
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/strings/range/set`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "greeting",
offset: 6,
value: "world"
})
});
const data = await response.json();
console.log(data);Get and Expire
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/strings/get-and-expire`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "session:123",
ttl_ms: 60000
})
});
const data = await response.json();
console.log(data);Set ttl_ms to 0 to persist the key while returning the value.
Get and Delete
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/strings/get-and-delete/session:123`, {
method: "DELETE",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
}
});
const data = await response.json();
console.log(data);Command Compatibility
If you need direct command access, use:
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/strings/command`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
command: "SET",
args: ["mykey", "hello world", "EX", "3600"]
})
});
const data = await response.json();
console.log(data);Command Endpoints
POST /[id]/strings/command
Execute allowed string commands across the plate.
Allowed Commands:
| Command | Description |
|---|---|
| GET | Get value |
| SET | Set value |
| MGET | Get multiple values |
| MSET | Set multiple values |
| GETEX | Get and optionally set expiry |
| GETDEL | Get and delete |
| INCR | Increment by 1 |
| DECR | Decrement by 1 |
| INCRBY | Increment by integer |
| DECRBY | Decrement by integer |
| INCRBYFLOAT | Increment by float |
| APPEND | Append to string |
| STRLEN | Get string length |
| SETRANGE | Replace substring |
| GETRANGE | Get substring |
Request:
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/strings/command`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
command: "INCR",
args: ["counter"]
})
});
const data = await response.json();
console.log(data);POST /[id]/strings/[key]/command
Execute allowed commands on a specific string key.
Allowed Commands: Same as above.
Request:
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/strings/mykey/command`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
command: "STRLEN"
})
});
const data = await response.json();
console.log(data);