Web services allow you to make HTTP requests to external third party websites.
For security reason, the external services must be configured on brainCloud.
To get started, find the Web Services on the brainCloud portal.
Click [+New Service] to show the Add Hook interface and fill out the essential fields.
Call HttpClient APIs To communicate with this service. There are several API request types are available on brainCloud system, GET, POST and PUT for cloud code for this time-being. You can find them from our api reference docs.
Test it from API Explore:
You can write a could code for your web service as well if you want, see the code example below:
// GetWeather script - takes the following parameters
// location - location to get the weather for - example "Ottawa, Canada"
// API key from WorldWeatherOnline.com
var key = "841664cedf0942afbe5164953200505";
// Path to the api method
var path = "free/v2/weather.ashx";
// Retrieve the HTTP Client proxy
var httpClientService = bridge.getHttpClientServiceProxy();
// Construct the query parameters (they will be automatically encoded in the URL)
var queryMap = {
"q": data.location,
"num_of_days": 1,
"format": "json",
"key": key
};
// No need to send anything specific in the headers
var headers = {};
// Make the request
var result = httpClientService.getResponseJson("getWeather", path, queryMap, headers);//make sure the name of Service match the one added at web services.
// Return the results
var retval = null;
if (result.status === 200)
{
retval = result.data.json.data;
//if use getResponseText instead of using getResponseJson, need change here accordingly
//retval = result.data.text;
}
retval;
Then test it from the script edit interface:
Or from s2s Explore if set this cloud code script s2s callable.
Or from an external browser, postman or whatever tools you prefer.