#summary Examples of how to use the gadgets.io.makeRequest functions = Introduction = In 0.7, `opensocial.makeRequest` was changed to `gadgets.io.makeRequest`. The following samples show how to make various queries with the new syntax. *Samples on this page use the `output` function syntax supplied by the [http://graargh.returnstrue.com/coderunner/ CodeRunner] gadget* = Details = ==Caching== Calls to `makeRequest` are cached. This wrapper function takes the same parameters as the `makeRequest` call, but accepts another parameter named `refreshInterval` which allows you to specify the cache duration. Specifying 0 will mean no caching. {{{ function makeCachedRequest(url, callback, params, refreshInterval) { var ts = new Date().getTime(); var sep = "?"; if (refreshInterval && refreshInterval > 0) { ts = Math.floor(ts / (refreshInterval * 1000)); } if (url.indexOf("?") > -1) { sep = "&"; } url = [ url, sep, "nocache=", ts ].join(""); gadgets.io.makeRequest(url, callback, params); } }}} You can call this function in places where you would use `gadgets.io.makeRequest()`, just put the extra parameter at the end of the method arguments. ==Responses== Responses come back as the following JavaScript object: {{{ { data : , errors : , text : } }}} ==Normal Requests== {{{ function makeNormalRequest() { var params = {}; params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT; var url = "http://graargh.returnstrue.com/buh/makerequest.php"; gadgets.io.makeRequest(url, response, params); }; function response(obj) { //obj.text contains the text of the page that was requested output(obj.text); }; makeNormalRequest(); }}} ==DOM Requests== {{{ function makeDOMRequest() { var params = {}; params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM; var url = "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml"; gadgets.io.makeRequest(url, response, params); }; function response(obj) { //obj.data contains a Document DOM element corresponding to the page that was requested output(obj.data); }; makeDOMRequest(); }}} ==JSON Requests== {{{ function makeJSONRequest() { var params = {}; params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON; var url = "http://graargh.returnstrue.com/buh/fetchme.php"; gadgets.io.makeRequest(url, response, params); }; function response(obj) { //obj.data contains a JavaScript object corresponding to the data that was requested output(obj.data); }; makeJSONRequest(); }}} ==Feed Requests== *Currently does not work on Orkut* {{{ function makeFeedRequest() { var params = {}; params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.FEED; var url = "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml"; gadgets.io.makeRequest(url, response, params); }; function response(obj) { //obj.data contains a JavaScript object corresponding to the feed that was requested output(obj.data); }; makeFeedRequest(); }}} ==POST Requests== {{{ function makePOSTRequest() { var params = {}; var postdata = { data1 : "test", data2 : 1234566 }; params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST; params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata); var url = "http://graargh.returnstrue.com/buh/makerequest.php"; gadgets.io.makeRequest(url, response, params); }; function response(obj) { output(obj.text); }; makePOSTRequest(); }}} ==Signed Requests== {{{ function makeSignedRequest() { var params = {}; params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED; var url = "http://graargh.returnstrue.com/buh/fetchme.php"; gadgets.io.makeRequest(url, response, params); }; function response(obj) { //obj.text contains the text of the response output(obj.text); }; makeSignedRequest(); }}}