post() Using Custom Content
Last updated 3/04/2024
The code is creating an instance of the HTTPClient
object using the function httpClient()
on the Five
object. The example will send a POST
request to
example.website.com with custom content.
Sending a POST request with custom content
function SendSimpleHttpPostRequest(five: Five, context: any, result: FiveError) : FiveError {
const webClient = five.httpClient();
////////////////////////////////////////////////////////////////////////////////////////////////
// Setting the content type
////////////////////////////////////////////////////////////////////////////////////////////////
webClient.setContentType(‘text/plain');
////////////////////////////////////////////////////////////////////////////////////////////////
// set the contents manually, ensuring that they adhere to the content type provided in the
// setContentType call above
////////////////////////////////////////////////////////////////////////////////////////////////
webClient.setContent('I am some text that will get posted to the website.');
////////////////////////////////////////////////////////////////////////////////////////////////
// We can post to a REST end the contents, and will be sent as text/plain
////////////////////////////////////////////////////////////////////////////////////////////////
const webResult = webClient.post(`https://example.website.com/createquoteoftheday`);
if (webResult.isOk() === false) {
return five.createError(webResult);
}
return five.success(result);
}
Sending a POST request with custom content
function SendSimpleHttpPostRequest(five, context, result) {
const webClient = five.httpClient();
////////////////////////////////////////////////////////////////////////////////////////////////
// Setting the content type
////////////////////////////////////////////////////////////////////////////////////////////////
webClient.setContentType(‘text/plain');
////////////////////////////////////////////////////////////////////////////////////////////////
// set the contents manually, ensuring that they adhere to the content type provided in the
// setContentType call above
////////////////////////////////////////////////////////////////////////////////////////////////
webClient.setContent('I am some text that will get posted to the website.');
////////////////////////////////////////////////////////////////////////////////////////////////
// We can post to a REST end the contents, and will be sent as text/plain
////////////////////////////////////////////////////////////////////////////////////////////////
const webResult = webClient.post(`https://example.website.com/createquoteoftheday`);
if (webResult.isOk() === false) {
return five.createError(webResult);
}
return five.success(result);
}