Building Apps with Jigx
...
Data
Data Providers
REST
14min
the rest data provider is one of the most frequently used data providers in {{jigx}} solutions 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) use the rest data provider to use the rest data provider in {{jigx}} , follow these high level steps 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 define a rest service in a {{jigx}} function in {{jigxbuilder}} navigate to the rest docid\ jrbansm ojn3nf4 dn hu folder in {{jigxbuilder}} use editor docid 5zrvshwiixwud2fbzsybv to configure the rest data provider enter the base url of the rest api configure rest authentication if the api requires rest authentication docid\ ckhjst84kd5 aylti0fhs (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 jigx functions in {{jig}} s rest docid\ jrbansm ojn3nf4 dn hu in your {{jig}} s this step is crucial for integrating the api data seamlessly into your {{jigx}} solution publish your solution publishing a solution docid\ ajp2syjvipjjdts01hu1t 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 {{jigxbuilder}} debugging docid\ psqdlve46kfecb4fzb6tb 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 jigx functions 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 provider data provider rest method post url "https //api sendgrid com/v3/mail/send" inputtransform > $ {"personalizations" \[{ "to" \[ { "email" emailto, "name" name }]}],"from" {"email" emailfrom, "name" name}, "reply to" {"email" emailfrom, "name" name },"subject" subject, "content" \[{ "type" "text/html", "value" content}]} parameters authorization location header type string value bearer xxxxxx required true emailfrom location body type string required true emailto location body type string required true name location body type string required true subject location body type string required true content location body type string required true referencing a jigx function here is an example of a jigx solution screen that calls the sendmail function we have not shown the entire {{jig}} , 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 title email employee icon synchronize arrows 1 type jig default header type component image options title keep employees updated source uri "https //www deputy com/uploads/2018/07/how to write an awesome welcome email for your new employee content image2 min 1024x569 png" actions \ children \ type action submit form options formid form three rest provider data provider rest title send updated info entity notify employee function rest send mail onsuccess title email has been sent description done actions \ type action go to options title employees linkto list four children \ type component form instanceid form three rest options children \ type "component text field" instanceid name options label "employee name" ishidden true initialvalue jigx team \ type "component text field" instanceid emailfrom options label email from ishidden true initialvalue 'john\@jigx com' \ type "component text field" instanceid emailto options label "email to " initialvalue =@ctx jig inputs employee user email \ type "component text field" instanceid subject options label "subject" ishidden true initialvalue 'employee information updated' \ type "component text field" instanceid message options label "message" ismultiline true textarea large 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 supporting json input and output 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 { "personalizations" \[ { "to" \[ { "email" "anemail\@com" } ] } ], "from" { "email" "youremail com" }, "subject" "sending with sendgrid is fun", "content" \[ { "type" "text/plain", "value" "and easy to do anywhere, even with curl" } ] } 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 provider data provider rest method post url "https //api sendgrid com/v3/mail/send" inputtransform | $ {"personalizations" \[{ "to" \[ { "email" emailto, "name" name }]}], "from" {"email" emailfrom, "name" name}, "reply to" {"email" emailfrom, "name" name }, "subject" subject, "content" \[{ "type" "text/html", "value" content}]} parameters authorization location header type string value bearer sg testingtestingdemo 2kyqyofa bpwlpjbuwtntwhls5pul voa22gw1koeiy required true emailfrom location body type string required true emailto location body type string required true name location body type string required true subject location body type string required true content location body type string required true 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 jsonata in input and output transforms 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 provider data provider rest method get url "https //www googleapis com/youtube/v3/playlistitems" outputtransform | $ items\[] {"id"\ id, "videoid" snippet resourceid videoid, "publishedat" $tomillis(snippet publishedat), "title" $contains(snippet title, "]") ? $trim($substringafter(snippet title, "]")) $trim(snippet title) , "description" snippet description, "thumbnail" $exists(snippet thumbnails maxres) ? snippet thumbnails maxres url snippet thumbnails high url} parameters key location query type string value aizasybaqf3e1qamsrjqgl99q5kkpa onhdgie required true playlistid location query type string value pl 500m6wb0wjtjkdom g7mkiqlwtvcm0o required true part location query type string value snippet required true maxresults location query type string value "500" required true 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 {{jig}} the $ eval() is used to return the individual ingredients outputtransform > { "id" $ recipes id, "name" $ recipes title, "image" $ recipes image, "desc" $ recipes summary, "ingredients" $map($ recipes extendedingredients, function($ingredient, $idx, $arr) { { "name" $ingredient name } }), "instructions" $map($ recipes analyzedinstructions steps, function($instruction, $idx, $arr) { { "step" $instruction step } }) } list jig jigx type component section options title ingredients children \ type component list options data =$eval(@ctx datasources randomrecipedata ingredients) item type component list item options title =@ctx current item name \# {"name" $ingredient name} \# }) examples and code snippets the following examples with code snippets are provided example create an app using rest apis docid\ b2bbvqccxto o9vuahx2a in this section, a rest api is used to create a customers {{jigx}} app, allowing you to add new customers and update and view customer details, location, and images ms graph docid\ qayypy4gqkxy2xw16ygpw the ms graph examples use the user, calendar, mail, insights, and to do tasks to create a powerful {{jigx}} apps with everything you need in one app building a rest based app video resources 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 see also file handling docid\ ugaq4ae3icfrecrwfif01 offline remote data handling docid\ h36q0e3t93lcbn9wejmjp