REST
The REST data provider allows you to fetch or post data to and from REST services that return JSON, XML, or binary data (or accept JSON, XML, or binary data).
- Choose your data source
- Identify the REST API you will use as your data source. Ensure you understand its endpoint structure, request requirements (like headers and query parameters), and the format of the data it returns.
- Enter the base URL of the REST API.
- Configure REST Authentication:
- If the API requires authentication (such as OAuth, API keys, etc.), configure these settings. This might involve adding headers, query parameters, or setting up OAuth tokens.
- Define data operations in the function:
- Set up different operations your application can perform using this API, such as GET, POST, PUT, DELETE, etc.
- For each operation, create a new function to specify the endpoint, required headers, URL parameters, input and output transforms, continuation, and body content if applicable.
- Reference the function in your s. This step is crucial for integrating the API data seamlessly into your solution.
- Publish your solution:
- Publish your solution and use the app to interact with the REST data provider. Make sure to handle any API limits or errors gracefully.
- Test the Data Provider:
- Use developer tools to test the data provider configurations. Check if the data provider can connect to the API successfully and perform operations like GET (fetch), PUT (create), POST (update), or DELETE data.
Following these steps, you can effectively integrate external REST APIs into your Jigx solutions, allowing you to enhance your apps with data and functionalities from diverse external sources.
The Jigx function contains the URL of the REST service, details of the required parameters, and an ability to MAP your Jigx parameters to complex JSON for either input or output purposes. In the sections below, we will explain each part of the function definition and how you can define any REST service and use it within your Jigx application. Here is an example of a Jigx function to send an email:
Here is an example of a Jigx solution screen that calls the sendmail function. We have not shown the entire , but you can see the call to the REST service within the actions section of the form below, which calls the function rest-send-email and sends each field in the form as a parameter to the REST service.
Jigx supports the concept of a REST service within a form context where each field in the form becomes a parameter, or alternatively, you can call the REST API using a Jigx function using the execute entity action, where you set the function parameters as part of the functions call in YAML.
REST services typically have simple or complex JSON structures which enable you to provide them with suitable input data as well as return complex data structures. Jigx has built-in capabilities to deal with these structures. These are achieved using:
- Input transforms
- Output transforms
Here is an example of a typical REST service from POSTMAN. This is the “Twilio sendgrid” service to send an email. The URL for the service is https://api.sendgrid.com/v3/mail/send
The JSON body for this service is:
This is an HTTP POST example and needs an Input Transform in order to map the data from a {} (for example, an employee form) so that it can send an email to an employee. Continuing from the example above, here is the input transform that maps fields on the form to the JSON body described above:
The same logic can be applied to the output from a REST service. The output transform processes JSON data returned by the REST service in the Jigx function definition.
In addition to applying basic “structural” transforms, the JSONata scripting capability is available to apply further functions, and logic transforms within the input and output transforms. More detail on JSONata can be found here: https://www.jsonata.org. Below is an example of a JSONata function applied within an output transform that returns videos from the Google YouTube API. Note the use of the $trim() and $substring() functions which provide further rich capability for JSON transforms.
Here is another example of an output transform used to return ingredients from a recipe in a single list-item (on single row). Note the use of $.map and function($ingredient, $idx, $arr). When using the returned data in a list the $.eval() is used to return the individual ingredients.
The following examples with code snippets are provided:
Example | |
Hello REST | |
MS Graph |
1. Introduction to REST API 6:59 min
2. Exploring REST and JSONata 6:17 min
3. Building a REST based App 9:14 min