Anyone make REST calls from Aware?

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
BLOMASKY
Posts: 1473
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Anyone make REST calls from Aware?

Post by BLOMASKY »

I have a need to make a REST call from within Aware. (I am not really worried about the result, but this will allow me to do some "neat" stuff on my server. Before I re-invent things, wonder if anyone else has done this?

It looks like the best approach would be to use JQuery Ajax calls. I do need to use a different port (where my Node.JS server is listening.) Searching the web, I do see some CORS examples like:


$.ajax({
type: "PUT",
url: "http://localhost:8080/some/url/resource/path",
contentType: "application/json",
data: JSON.stringify({
name: "Tricia",
age: 37
}),
dataType: "text",
success: function( response ){
// Put the plain text in the PRE tag.
$( "#putResponse" ).text( response );
},
error: function( error ){
// Log any error.
console.log( "ERROR:", error );
},
complete: function(){
// When this completes, run someFunction
someFunction();
}
});
};

Does this make sense to you JQuery experts?

Thanks
Bruce
UnionSystems
Posts: 197
Joined: Fri Jun 17, 2016 7:10 am
Location: Brisbane Australia
Contact:

Re: Anyone make REST calls from Aware?

Post by UnionSystems »

Hi,

I've been using JavaScript and Ajax as per your example to pass data in both directions between non AwareIM website forms and the generic AwareIM REST interface. Works fine and avoids having to use iframes around Aware forms.

What I have struggled with in AwareIM is consuming other external REST services. General advice has been to build Java plugins but that is beyond me.

I've started having success doing the following with Python scripts on my Linux server:

1. Creating Text document templates to construct simple Python scripts embedded with AwareIM data using <<Object.Attribute>>
2. EXPORTIng those document templates to a temporary directory
3. Executing them with EXECUTE_PROGRAM ('Python name of script')
4. Importing the CSV the scripts create back into Aware IM business objects

I've only been using Python for a few days but there are heaps of simple examples on the web that have made it fairly straight forward. Python comes with a some very helpful modules to make this happen. REQUEST lets you make web service calls including uploading files. JSON lets you parse JSON and CSV helps with manipulation of ....CSV
AWS Linux, Windows Server, AIM 8.4 & 8.6
BenHayat
Posts: 2749
Joined: Thu Dec 23, 2010 5:48 am
Location: Fla, USA
Contact:

Re: Anyone make REST calls from Aware?

Post by BenHayat »

UnionSystems wrote:Hi,

I've been using JavaScript and Ajax as per your example to pass data in both directions between non AwareIM website forms and the generic AwareIM REST interface. Works fine and avoids having to use iframes around Aware forms.
David, how do you authenticate the calls and making sure a caller is loggedin and authenticated to access Aware data?
UnionSystems
Posts: 197
Joined: Fri Jun 17, 2016 7:10 am
Location: Brisbane Australia
Contact:

Re: Anyone make REST calls from Aware?

Post by UnionSystems »

We've been using the Ajax REST forms for casual registrations of new data (Event registration forms) so no authentication has been required. If I were to use REST forms to allow a person to access and update their data set (eg amend their registration details) I'd allocate them a long random access key and include it as a hyperlink in their registration receipt email. Then I'd have a process sitting behind a separate REST call on AwareIM that would inspect that request and match the user to the access key before displaying their data set. Once a user needs accessed to enough data I'd look to promote them to using normal Aware IM screens.

I think a REST form is a good solution for simple public facing forms that need particular usability and/or mirror the aesthetics of their hosting website. If you need serious data access for the person stick to using real Aware IM screens.
AWS Linux, Windows Server, AIM 8.4 & 8.6
BenHayat
Posts: 2749
Joined: Thu Dec 23, 2010 5:48 am
Location: Fla, USA
Contact:

Re: Anyone make REST calls from Aware?

Post by BenHayat »

David, watch the first "Preview" video and pay attention when the guy talks about chapter/section 5 on security. This is what concerns me about making REST calls to Aware.

https://www.udemy.com/learning-aspnet-web-api/
BLOMASKY
Posts: 1473
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: Anyone make REST calls from Aware?

Post by BLOMASKY »

Hi Guys. Spent the last couple of days playing with and "tweaking" my calls to REST from Aware and all is good

What I accomplished, is:

* I have a Node Express Server listening on a specific port
* When I issue a post, it will call a Jasper Report, Pipe the output to a file then will email this file to someone who's email has been passed to the post call
* Since this is an intranet, I don't have many security issues, but would be easy to send a token for the user / pswd to be validated prior to running the report

This is working well, and is fast and slick. If anyone else is looking to do something similar, let me know and will be happy to share.

Bruce
RLJB
Posts: 914
Joined: Tue Jan 05, 2010 10:16 am
Location: Sydney, Australia

Re: Anyone make REST calls from Aware?

Post by RLJB »

We have a reasonably elaborate (but bullet proof) method we have developed over the past 18 months to do similar:

1. We use AWS API Gateway and Lambda functions written in node.js, we also have an RDS MySQL DB set up (none of that is mandatory but we find it useful and flexible)

2. We got an Aware function written called POST_CONTENTS it is very similar to the URL_CONTENTS but instead of doing a GET it does a POST with the payload being an Aware attribute

3. We use the function to POST either directly to the external Restful API we are working with, or if it is complex (requires auth, or stuff that is tricky to do in Aware) we build an AWS Lambda function, which we POST to and the Lambda function sits between Aware and the API and does what it needs to.

4. Sometimes - if it's a complex response from the API - we will get the AWS Lambda function to write the API response to an RDS table and we get Aware to tap into that externally and import the data. This is useful where the response has lots of JSON and pulling it apart with Aware rules is hard.

To be honest, this isn't an ideal situation, I would prefer that more was done in Aware to support pulling apart the Json responses and even building them. I guess we will consider building some more functions in the future will solve this, a function that did oAuth, that built a JSON payload more easily, further refinement of our POST_CONTENTS function to allow for custom built headers on the fly, and a function to get a JSON response and put it into attributes, all these would make this a much nicer solution. If only we had limitless time and money.
Rod. Aware 8.6 (latest build), Developer Edition, on OS Linux (Ubuntu) using GUI hosted on AWS EC2, MYSQL on AWS RDS
Post Reply