API Examples
Important: We're currently in our open phase. While anyone can retrieve data (GET requests) from any domain thanks to our CORS support, new data creation (POST requests) from browsers is only possible through our official jsondb.cloud interface. API-based and server-side POST requests are not affected by this limitation.
cURL Example
Use cURL to store and retrieve JSON data. Perfect for quick testing or shell scripts.
# Store JSON curl -X POST https://jsondb.rest/api/v1/ \ -H "Content-Type: application/json" \ -d '{"hello": "world"}' # Response: # {"url": "0a1b2c3d-4e5f-6g7h-8i9j-0k1l2m3n4o5p.json"} # Retrieve JSON curl https://jsondb.rest/api/v1/0a1b2c3d-4e5f-6g7h-8i9j-0k1l2m3n4o5p.json # Response: # {"hello": "world"}
JavaScript Fetch Example
Modern async/await example using the Fetch API. Works in both Node.js and browsers.
// Store JSON async function storeJson() { const response = await fetch('https://jsondb.rest/api/v1/', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ hello: 'world' }) }); const data = await response.json(); // data.url contains the GUID return data.url; } // Retrieve JSON async function getJson(guid) { const response = await fetch(`https://jsondb.rest/api/v1/${guid}`); const data = await response.json(); return data; } // Usage example async function example() { try { // Store the JSON const guid = await storeJson(); console.log('Stored at:', guid); // Retrieve the JSON const data = await getJson(guid); console.log('Retrieved:', data); } catch (error) { console.error('Error:', error); } }