< Previous Article

pjs.httpRequest()

This API was added in Profound.js 6.1.0. This API replaces pjs.sendRequest(), which is now deprecated.

The pjs.httpRequest() 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.httpRequest({
  method: "POST",
  uri: "/updatePrice"
  body: {
    price,
    effectiveDate: new Date()  // today
  }
});

GET example using an absolute URI:

// Get exchange rate data
let response = pjs.httpRequest({
  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.

< Previous Article