Presto Development and APIs : Working with the Presto REST API : Build and Send the Request
Build and Send the Request
Take the URL from the Technical Specs for the mashable or mashup and:
*Update any of the parameters, as needed.
You can set parameter values programmatically, or use Presto attributes to have the Presto Server resolve parameter values. See Map Presto Attributes to Artifact Input Parameters for more information.
*Remove or add Presto Headers/Parameters to control aspects of request processing or specific information in the response.
Some of the most common headers include:
*x-p-resultFormat to have Presto send the result in CSV, JSON or XML format. If you don’t add this header, Presto returns the response in the native format of the mashable for mashup.
*x-p-anonymous=true to have Presto treat this request as coming from a guest user with no identity.
*Headers to have Presto paginate the response.
*Headers to override the credentials to use for a secure connection with a mashable.
Mashables are registered with credential information when the service requires authentication, but you can override these default credentials using Presto headers.
Using jQuery, for example, the request would look something like this:
var requestBody = '';
var params = "p=" + this.zip;
var headers= "x-p-resultFormat=json&x-p-anonymous=true";

var invokeUrl = "/presto/edge/api/rest/YahooWeatherREST/getData?" + headers + "&" + params;

jQuery.ajax({
type: "get",
contentType: "application/x-www-form-urlencoded",
url: invokeUrl,
data: requestBody,
dataType: "text",
success: function(response){
var result = response;
if(typeof response !== "string") {
result = Object.toJSON(response);
}
jQuery("#result").val('' + result);//show response
},
error: function(xhr, errorStatus, e) {
jQuery("#result").val(xhr.responseText);//handle error
}
});
If the mashable or mashup uses HTTP POST, you must also build the body of the request to match what the mashable or mashup is expecting.
Copyright © 2013-2015 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback