Skip to main content

post() Using Custom Content

Last updated 2/10/2024

The following code is creating an instance of the

object using
httpClient()
on the
Five
object. The example will send a

POST
request to example.website.com with custom content.


note

The following code holds examples for the functions:

  • post()
  • httpClient()
  • setContent()

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("Don't put all your eggs in the one basket.");

////////////////////////////////////////////////////////////////////////////////////////////////
// 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);
}