REST API
With Cragvale, you store various different data and files in buckets using three different Application Programming Interfaces (APIs) which you can use based on your specific needs.
Cragvale buckets are not to be confused with buckets used by AWS S3 type services, there is no file manager or way to connect a file manager to said buckets on Cragvale. Instead, our service is aimed at website and app developers who need to store information in an easily retrievable and sortable manner. Our service is closest to Google Firestore, Datastore, or Firebase. We use an AWS S3 compatible buckets system on our backend in order to store all of your data in an organized manner all in one place. We allow you to create and access said buckets via our APIs.
Our API does not need you to include or install any special API software, unlike with Firebase, Cloud Firestore, etc. as you can access our API using simple HTTP POST using a multitude of available existing methods such as but-not-limited-to:
- Curl
- JavaScript fetch API (Node.js / Deno)
Security Notice
It is strongly advised that you use server side code when interfacing with the API so to not expose your authentication details!
Blob storage allows for you to upload files using binary formatting which may include images, programs, zip files, apps, and more. Cragvale stores your blob data as base64 encoded data.
Blob file names can not have extensions. You could keep track of file types using the following methods:
- Attaching the extension to the front of the file data after base64 encoding it png^RHVkZQ== then striping the png^ before base64 decoding.
- Using a Key/Value store entry with the file name as the key and the value being file extension myFile1 = png
You may use the following in your key names: numbers 0-9, upper and lowercase letters, and hyphens.
HTTP POST URL: https://dds.cragvale.org/setBLOB
POST BODY:
JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "", "authSecret": "" }, "data": base64Data, "path": "folder/myFile" });
const fileData = fs.readFileSync("path/to/your/file.png"); const data = new Blob([fileData], { type: "image/png" }); const base64Data = Buffer.from(data).toString('base64'); const response = await fetch('https://dds.cragvale.org/setBLOB', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "", "authSecret": "" }, "data": base64Data, "path": "folder/myFile" }); });
HTTP POST URL: https://dds.cragvale.org/getBLOB
POST BODY:
JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "9YB1OTS90M5XAOOI5JNF", "authSecret": "jyFNiHjE76CRxGIGZ7fz7Yx0QRklft8RNbhaNMle" }, "path": "TestFolder/TestDocument2" });
const response = await fetch('https://dds.cragvale.org/setBLOB', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "9YB1OTS90M5XAOOI5JNF", "authSecret": "jyFNiHjE76CRxGIGZ7fz7Yx0QRklft8RNbhaNMle" }, "path": "TestFolder/TestDocument2" }); }); const myFile = response.data; // base64 encoded data, you can then send it to the web browser
// Web browser code
const base64Data = myFile.replace(/^data:.+;base64,/, ''); const byteCharacters = atob(base64Data); // Decode Base64 string const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) { byteNumbers[i] = byteCharacters.charCodeAt(i); }
const byteArray = new Uint8Array(byteNumbers); const blob = new Blob([byteArray], { type: "image/png" }); const url = URL.createObjectURL(blob);
// Create a link element to download the file const link = document.createElement('a'); link.href = url; link.download = fileName; link.click(); // Cleanup URL.revokeObjectURL(url);
HTTP POST URL: https://dds.cragvale.org/deleteBLOB
POST BODY:
JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "9YB1OTS90M5XAOOI5JNF", "authSecret": "jyFNiHjE76CRxGIGZ7fz7Yx0QRklft8RNbhaNMle" }, "path": "TestFolder/TestDocument2" });
const response = await fetch('https://dds.cragvale.org/deleteBLOB', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "9YB1OTS90M5XAOOI5JNF", "authSecret": "jyFNiHjE76CRxGIGZ7fz7Yx0QRklft8RNbhaNMle" }, "path": "TestFolder/TestDocument2" }); });
JSON datastore uses a path styled referencing engine which allows you to store JSON data at specific addresses. Documents can be up to 1 MB in size and keys can be up to 6 KB in size. Documents are stored in the JSON-API folder in the root of your bucket, so remember to not delete that folder!
You can place the document into a folder by adding folder name in front of the document name:
"document": "myFolder/subFolder/myDocument"
This is not to be confused with "path" which is the JSON path within the document.
The special feature of the JSON store is path traversal. Take for instance you have a document named "Accounts" and it has the structure similar to below:
{ "users": [ { "name": "David", "age": 27 }, { "name": "Harry", "age": 43 } ] }
If you provide an empty path "" you will get the entire document contents as shown above, but if you want to drill down and get only "users" you would specify a path of "/users" which would return only [{ "name": "David", "age" 27 }, { "name": "Harry", "age": 43 }]. Soon you will also be able to drill down into arrays as well by doing "/users[1]" which would return { "name": "Harry", "age": 43 }.
HTTP POST URL: https://dds.cragvale.org/setJSON
POST BODY:
JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "", "authSecret": "" }, "data": { "first name": "Sam", "last name": "Daniels", "age": 23 }, "path": "key1/key2" });
const response = await fetch('https://dds.cragvale.org/setJSON', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "", "authSecret": "" }, "data": { "first name": "Sam", "last name": "Daniels", "age": 23 }, "document": "MyDocument", "path": "key1/key2" }); });
HTTP POST URL: https://dds.cragvale.org/getJSON
POST BODY:
JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "9YB1OTS90M5XAOOI5JNF", "authSecret": "jyFNiHjE76CRxGIGZ7fz7Yx0QRklft8RNbhaNMle" }, "document": "MyDocument", "path": "key1/key2" });
const response = await fetch('https://dds.cragvale.org/getJSON', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "", "authSecret": "" }, "document": "MyDocument", "path": "key1/key2" }); });
HTTP POST URL: https://dds.cragvale.org/deleteJSON
POST BODY:
JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "9YB1OTS90M5XAOOI5JNF", "authSecret": "jyFNiHjE76CRxGIGZ7fz7Yx0QRklft8RNbhaNMle" }, "data": { "k": "name" }, "document": "myDocument", "path": "key1/key2" });
Deleting a single key:
const response = await fetch('https://dds.cragvale.org/deleteJSON', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "bucket": "myBucket", "cedentials": { "authToken": "9YB1OTS90M5XAOOI5JNF", "authSecret": "jyFNiHjE76CRxGIGZ7fz7Yx0QRklft8RNbhaNMle" }, "data": { "k": "name" }, "document": "myDocument", "path": "key1/key2" }); });
Deleting an entire path:
const response = await fetch('https://dds.cragvale.org/deleteJSON', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "9YB1OTS90M5XAOOI5JNF", "authSecret": "jyFNiHjE76CRxGIGZ7fz7Yx0QRklft8RNbhaNMle" }, "document": "myDocument", "path": "key1/key2" }); });
As you can see above that we left out the data property which tells the delete function to remove key2 and everything it contains. If you was to specify a path of just TestFolder, it would remove key1 and everything it contained including key2 and all of it's contents. And if you specified an empty path string, then the entire document would be emptied. Omitting the path property entirely will result in the document itself being deleted.
Key/Value pairs is a simple type of data storage where you store a string of data under a given key. Keys can be of many styles including numerical, alpha-numerical, alpha, UUID, or some other randomly generated alpha-numeric value. Documents are stored in the KV-API folder in the root of your bucket, so remember to not delete that folder!
HTTP POST URL: https://dds.cragvale.org/setKV
POST BODY:
JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "", "authSecret": "" }, "data": { "k": "name", // The key for your data would be name in this instance "v": "Dude" // The value for name would be Dude }, "path": "folder/myFile" });
const response = await fetch('https://dds.cragvale.org/setKV', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "", "authSecret": "" }, "data": { "k": "name", // The key for your data would be name in this instance "v": "Dude" // The value for name would be Dude }, "path": "folder/myFile" }); });
HTTP POST URL: https://dds.cragvale.org/getKV
POST BODY:
JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "", "authSecret": "" }, "data": { "k": "myKey" // key within the file that you wish to fetch }, "path": "folder/myFile" });
const response = await fetch('https://dds.cragvale.org/getKV', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "", "authSecret": "" }, "data": { "k": "myKey" // key within the file that you wish to fetch }, "path": "folder/myFile" }); });
HTTP POST URL: https://dds.cragvale.org/deleteKV
POST BODY:
JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "9YB1OTS90M5XAOOI5JNF", "authSecret": "jyFNiHjE76CRxGIGZ7fz7Yx0QRklft8RNbhaNMle" }, "data": { "k": "keyName" }, "path": "TestFolder/TestDocument2" });
const response = await fetch('https://dds.cragvale.org/deleteKV', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ "bucket": "myBucket", "credentials": { "authToken": "9YB1OTS90M5XAOOI5JNF", "authSecret": "jyFNiHjE76CRxGIGZ7fz7Yx0QRklft8RNbhaNMle" }, "data": { "k": "keyName" }, "path": "TestFolder/TestDocument2" }); });
Our JSON based hierarchy storage allows you to store data in a relationship of parent and child nodes.
Will will be adding this feature soon, so stay tuned!
HTTP POST URL: https://dds.cragvale.org/saveHier
POST BODY:
HTTP POST URL: https://dds.cragvale.org/getHier
POST BODY:
HTTP POST URL: https://dds.cragvale.org/deleteHier
POST BODY:
WebSocket API
We will be adding a WebSocket based API as another means for web/app developers to connect and store data.
In addition to storing data, you can also subscribe to data change events so that you can act upon changes to your data.
More on this will be forthcoming!