Making AJAX and External Data Requests

During normal program flow, you may need to modify your application or augment the server data sources, such as a database, with new content. To meet this need, OpenSocial makes available an http request method through the standard JavaScript library.

Developers can use this method to make RESTful requests (GET, PUT, POST, DELETE) between the application and the server to alter their state without impacting the user experience.

The methods you can use to make these requests are all under the osapi.http object and include:

  • osapi.http.get(url, params)

  • osapi.http.put(url, params)

  • osapi.http.post(url, params)

  • osapi.http.delete(url, params)

In addition to the URL to make the http request to, there are a number of parameters you can introduce within these request calls. They are listed in Table 6-2.

Table 6-2. http request parameters

Parameter

Description

authz (string)

The authorization method to use when sending data to the server. This value may be none (default), signed, or oauth.

body (string)

For PUT and POST requests. The data to be sent to the server from the request.

format (string)

The format of the data returned. This value may be json (default) or text.

headers (string/array of strings)

Optional headers to send with the data request.

oauth_service_name (string)

The service element in the gadget spec to use for the request. Default is an empty string (" ").

oauth_token_name (string)

The OAuth token to use in the request. Default is an empty string (" ").

oauth_request_token (string)

A token that is preapproved by the provider for accessing the content of the request.

oauth_request_token_secret (string)

The secret associated with the request_token.

oauth_use_token (string)

Should the OAuth token be used in the request? Possible values are always, if_available, or never.

refreshInterval (integer)

Period of time for which the container may cache the return data.

sign_owner (Boolean)

Should the request be signed and pass the owner ID? Default is true.

sign_viewer (Boolean)

Should the request be signed and pass the viewer ID? Default is true.

Many of the requests used for insecure data will include only a small portion of these parameters, including format, body for POST or PUT requests, and refreshInterval to increase performance.

The authz, sign_*, and oauth_* parameters may be introduced to the request if you need to make a secure data request and verify the sender’s identity.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.62.122