Usecase: we will show how to access data from an external REST service using service connection - Define by endpoint option.
Highlevel steps:
- Create a service connection to an external rest endpoint
- Create a type and variable from the rest endpoint
- Add fields to the employees edit page to display country data
- Bind the created country avatar, input fields to the created country type variables.
- Assign data to variables
- Test the employee's country details
Implementation steps:
Step1: create a service connection to an external rest endpoint
Web apps >> Services >> click + service connection >> wizard will show 3 options >> select define by endpoint >> select method, provide URL and select action >> create backend
Here, we have mentioned below details:
Method: get
URL: https://restcountries.com/v2/alpha/{code}
action: Get one
In the backend spwcfication step >> enter backend name : countries, select authentication if any. Contion type as Dynamic the service supports CORS. >> next
In create service connection page, provide service name and title and click test
Provide value >> click send request >> save as example response >> create
Step2: create a type and variable from the rest endpoint:
Types tab >> click + type >> select from endpoint >> expand services >> countries >>select GET /alpha/{code} endpoint >>next >> select the fields to display from the response. >> finish
Right click on the newly created countryType >> select create variable
Step3: add fields to the employee's edit page to display country data
We will change the edit employee page to show information about an employee's country.
Web applications >> open the main-editemplyee page >>> drag and drop heading component from component pallet to the page at the end of the form layout. >> change the text field value to country info and move the slider H1to H6. >> drag and drop form layout from component pallet. >> now add avatar and input text fields for timezone and region
Step4:Bind the created country avatar, input text fields to the countryType variable
Go to the page designer >> select avatar >> click data tab >> src field >> select the created country type variable and flag >> sameway for region and timezone and src >> add the variables
Step5: assign data to the variable
Select country field data >> add on value event that triggers an action chain >>>> from where we use rest call action and select the endpoint service >> assign input parameter >> expand employee under page and map country to code. >> drag and drop assign variable >> select countrytypevar >> which maps to callrest response body
Step6: testGo to preview and test with country data IN or IE ETC.