Skip to main content

Test Response Data in Your Application

Last updated 4/09/2025

The previous chapter, Securing Public URLs, demonstrated how to get the response data from your Five application in Postman. This documentation will demonstrate how you can test the response data in your Five application when a Bearer Token is required.

The following will need to be added into the External URL Data Access application built in Five to enable you to test the response data from your URL endpoint:

TestExternalURL Function

The example function is called

TestExternalURL()
and will log the response data to Five's Inspector.

The

function is used on the

Five
object to pass in the value of the associated key. For this example, the
accessToken
key is passed into the function to get the Bearer Token value. The Bearer Token authorization is stored as a key: value pair on the instance record.

The

function is used on the

Five
object to instantiate an instance of the
HTTPClient
object enabling communications between the client and the server.

The

function is used on the

HTTPClient
object to let the client pass the additional information of the Bearer Token authorization.

The

function is used on the

HTTPClient
object to send a
GET
request to the published external URL.

The

function is used on the

Five
object to create an error if the external URL can't be accessed.

The

WebResult
object contains the returned results from the request and is attached to the
results
key on the
Response
object.

The

function is used on the Five object to log the results to Five's Inspector.

Add the TestExternalURL Function

1. Click the Add Item button and give your function an ID (TestExternal URL) in the Function ID field.

2. Click in the Code field.


Add TestExternalURL function
Figure 1 - Add TestExternalURL function

3. Click the Copy button on the below code block

JavaScript
Test the reponse data
function TestExternalURL(five, context, result)  {
////////////////////////////////////////////////////////////////////////////////////////////////
// create the http client to test our external url
////////////////////////////////////////////////////////////////////////////////////////////////
const accessToken = five.getOptionServer('accessToken');
let webClient = five.httpClient();
webClient.addHeader('Authorization', `Bearer ${accessToken}`);
const webResult = webClient.get('https://control-default-externalurldata-jo.5au.dev/action/customers');
if (webResult.isOk() === false) {
return five.createError(webResult, 'Failed to access external url');
}

////////////////////////////////////////////////////////////////////////////////////////////////
// log the results so we view them in the inspector
////////////////////////////////////////////////////////////////////////////////////////////////
five.log('Testing External URL Results');

// the webResult object contains the results returned from the request, this is attached to the results key
// on the response object of the webResult object, this data will be JSON data that has been stringified
// and will need to be Parsed back to a JSON object
const response = JSON.parse(webResult.response.results);

// the response now contains an object containing the array of customers that was attached in the external URL
// function
const customers = response.customers;
for (let i = 0; i < customers.length; i++) {
five.log('Customer (FirstName) : '+ customers[i].FirstName + ", " + customers[i].LastName);
}

return five.success(result);
}

4. Paste the code block over the template in the Code Editor.

5. Click the Save button in the Code Editor app bar.


Save TestExternalURL code
Figure 2 - Save TestExternalURL code

6. Click the Save button in the form app bar.


Save TestExternalURL function
Figure 3 - Save TestExternalURL function

Add the Test URL Button

A button called Test URL needs to be added to the Customers list, when the button is clicked the response data will be available in Five's Inspector.

1. Select Visual in the menu followed by Forms in the sub-menu.


Forms menu item
Figure 4 - Forms menu item

2. Select the Customers record in the list and click the Action Buttons tab.


Action Buttons tab
Figure 5 - Action Buttons tab

3. Click the Add Action Buttons button.


Add Action Buttons button
Figure 6 - Add Action Buttons button

4. Give your button a caption (Test URL) in the Caption field.

5. Click the lookup icon in the Action Area field and select List.


Add Test URL button
Figure 7 - Add Test URL button

6. Click the Events tab.


Events tab
Figure 8 - Events tab

7. Click the lookup icon in the Do Press field and select your function (TestExternalURL).

info
The
TestExternalURL()
function is a backend function, so it must be attached to the Do Press event.

Do Press field
Figure 9 - Do Press field

8. Click the Save button in the form app bar.


Save button
Figure 10 - Save button

9. Click the Save button in the form app bar above the list.


Save button
Figure 11 - Save button

Response Data

You can now deploy your application and use the Test URL button to see the response Data in Five's Inspector.

1. In your running application, click the Profile button followed by the Inspector button.


Inspector button
Figure 12 - Inspector button

2. Click on the Expand button to open Five's Inspector.


Expand button
Figure 13 - Expand button

3. Click the Test URL button.


Test URL button
Figure 14 - Test URL button


Response data
Figure 15 - Response data