< Previous Article Next Article >
pjs.sendRequest()
pjs.sendRequest() is deprecated. Please use pjs.httpRequest() instead.
The pjs.sendRequest() API consumes a RESTful web service using server-side code and returns the web service response.
The API accepts a configuration parameter with the following properties:
- method - the HTTP method to use (POST, GET, PUT, etc.)
- uri - the relative or absolute URI for the request
- body - request body or post data to pass along to the web service
POST example using a relative URI:
let response = pjs.sendRequest({
method: "POST",
uri: "/updatePrice"
body: {
price,
effectiveDate: new Date() // today
}
});
GET example using an absolute URI:
// Get exchange rate data
let response = pjs.sendRequest({
method: "GET",
uri: "https://api.exchangeratesapi.io/latest?base=" + baseCurrency
});
// Load Rich Display grid with exchange rates
for (let currency in response.rates) {
display.grid.push({
currency,
rate: response.rates[currency]
})
}
Questions?
Have questions about this topic? Ask for help on our Profound.js Spaces Discussion Forum.