/* javascript demo (Firefox), require "http://www.json.org/json2.js" */ var API_URL = 'http://api2.diigo.com/bookmarks'; var xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = onResponse; function onResponse() { if (xmlHttp.readyState == 4) { alert(xmlHttp.responseText); } } /* GET: query bookmarks */ function queryBookmarks() { xmlHttp.open("GET", API_URL + "?rows=1&users=foo", true); xmlHttp.send(null); } /* POST: create bookmarks */ function createBookmarks() { bookmarks = [ { "title":"Test Bookmark", "url":"http://www.example.com", "shared":"yes", "tags":"test", "desc":"just test" } ]; xmlHttp.open("POST", API_URL, true); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); xmlHttp.send("bookmarks=" + encodeURIComponent(JSON.stringify(bookmarks))); } /* PUT: update bookmarks */ function updateBookmarks() { bookmarks = [ { "title":"Test Bookmark 2", "url":"http://www.example.com", "shared":"no", "tags":"test", "desc":"just test" } ]; xmlHttp.open("PUT", API_URL, true); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); xmlHttp.send("bookmarks=" + encodeURIComponent(JSON.stringify(bookmarks))); } /* DELETE: delete bookmarks */ function deleteBookmarks() { urls = ["http://www.example.com", "http://www.example.com/1.html"]; xmlHttp.open("DELETE", API_URL, true); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); xmlHttp.send("urls=" + encodeURIComponent(JSON.stringify(urls))); }