Sets API
Unique member collections for tags, memberships, and feature flags
Sets store unique members with no guaranteed order. They are useful for tags, memberships, feature flags, and unique identity collections.
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /{plateId}/sets/add | Add members |
| POST | /{plateId}/sets/remove | Remove members |
| GET | /{plateId}/sets/members/{key} | Read all members |
| POST | /{plateId}/sets/contains | Check one or many members |
| GET | /{plateId}/sets/count/{key} | Count members |
| GET | /{plateId}/sets/random/{key} | Read random members |
| POST | /{plateId}/sets/pop | Pop random members |
| POST | /{plateId}/sets/union | Union or union-store |
| POST | /{plateId}/sets/intersect | Intersection or store |
| POST | /{plateId}/sets/diff | Difference or store |
| POST | /{plateId}/sets/command | Execute allowed set commands |
| POST | /{plateId}/sets/{key}/command | Execute key-specific set commands |
Examples
Add members
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/sets/add`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "tags",
members: ["red", "blue", "green"]
})
});
const data = await response.json();
console.log(data);Check one member
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/sets/contains`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "tags",
member: "red"
})
});
const data = await response.json();
console.log(data);Check many members
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/sets/contains`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
key: "tags",
members: ["red", "black"]
})
});
const data = await response.json();
console.log(data);Union without storing
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/sets/union`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
keys: ["team:a", "team:b"]
})
});
const data = await response.json();
console.log(data);Union and store the result
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/sets/union`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
keys: ["team:a", "team:b"],
destination: "team:all"
})
});
const data = await response.json();
console.log(data);Command Compatibility
const plateId = "[id]";
const apiKey = "your-api-key";
const baseUrl = "[base-url]";
const response = await fetch(`${baseUrl}/$[id]/sets/command`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
command: "SADD",
args: ["myset", "a", "b", "c"]
})
});
const data = await response.json();
console.log(data);Command Endpoints
POST /[id]/sets/command
Execute allowed set commands across the plate.
Allowed Commands:
| Command | Description |
|---|---|
| SADD | Add members |
| SREM | Remove members |
| SMEMBERS | Get all members |
| SISMEMBER | Check one member |
| SMISMEMBER | Check multiple members |
| SCARD | Get member count |
| SRANDMEMBER | Get random members |
| SPOP | Pop random members |
| SUNION | Union of sets |
| SINTER | Intersection of sets |
| SDIFF | Difference of sets |
| SUNIONSTORE | Union and store |
| SINTERSTORE | Intersection and store |
| SDIFFSTORE | Difference and store |
Query Parameters for SRANDMEMBER:
count(optional): Number of members to return (negative for distinct)
POST /[id]/sets/[key]/command
Execute allowed commands on a specific set 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]/sets/myset/command`, {
method: "POST",
headers: {
"Authorization": apiKey,
"Content-Type": "application/json"
},
body: JSON.stringify({
command: "SCARD"
})
});
const data = await response.json();
console.log(data);