Calling REST endpoint from OpenEdge

Posted by vinaynayak on 18-Sep-2015 11:52

I have to call a REST endpoint from OpenEdge DB trigger.

Looking for some code snippet or pointers. 

Thanks!

All Replies

Posted by Marian Edu on 18-Sep-2015 12:06

You most probably don't have nor should do this from a trigger, other than that REST means simply a HTTP request and depending on your OS/Progress versions you can go with an os-command to curl, make a socket connection over or use the new .Net package in 11.5+.  

Posted by vinaynayak on 18-Sep-2015 12:25

The idea is to know real time when changes have happened on database.

Would using curl be scalable?

Posted by Brian K. Maher on 18-Sep-2015 12:30

 
How would you handle transaction rollbacks?
 
 

Posted by TheMadDBA on 18-Sep-2015 14:07

As others have said.... Don't put the logic inside of the trigger. Rollbacks will be an issue because the rest call will not be rolled back with the data. You also have the real chance of transactions lasting much longer in the case of network errors or downstream issues.

Add a datetime column and populate it during the trigger. Or create queue records in the triggers. Then have one or more jobs that process the changed records and call the rest service.

Real time is essentially a myth for database applications. Near real time is as good as it gets for any non trivial application.

Posted by vinaynayak on 18-Sep-2015 14:16

"create queue records"? you mean create records in a special table, to work like a queue of DB events?

And consume those records to call REST?

Posted by Brian K. Maher on 18-Sep-2015 14:33

 
Vinay,
 
TheMadDBA is correct.
 
Create a special table with whatever fields you need then add records to this table in the triggers.  Doing it this way will automatically handle the removal of records when the transaction ends up getting rolled back.
 
You can then have a background process which handles the records in the table and invokes the REST service.  Be sure to process them with exclusive-locks so you don't touch records that are still part of an active transaction).
 
Brian
 
 
 

Posted by vinaynayak on 18-Sep-2015 14:54

Thanks!

- Would this idea scale for high volumes on transaction tables?

- Second, can one of you provide me a snippet of code to make the REST call from the background process.  I have my Progress DB deployed on Linux. so need a solution that does not need Windows.

Posted by Brian K. Maher on 19-Sep-2015 06:25

>> - Would this idea scale for high volumes on transaction tables?

Yes it would.

>> - Second, can one of you provide me a snippet of code to make the REST call from the background process.  I have my Progress DB deployed on Linux. so need a solution that does not need Windows.

On Linux your best bets would be to shell out and use CURL or (perhaps) use our HTTP classes, however, I haven't done much with them and am not certain that they work on non-Windows platforms.  Someone else would have to jump in on that point.

As far as code snippets, unfortunately I don't have any.  If you are not interested in trying to write the code yourself I would suggest that you use google, find some sample code (even if in a different language) then try converting that.

 

Posted by TheMadDBA on 19-Sep-2015 10:32

It will scale as well as you design it for multi threading and as your hardware allows. Make the wrong design choices and it will suffer.

cURL would be the easiest path since it handles pretty much everything by setting various options.

I would suggest doing quite a bit of testing before you deploy this in a production environment.

Posted by Irfan on 22-Sep-2015 08:29

cURL is pretty simple to use. But if you wish to use the ABL .NET Classes for invoking REST Services, then let me know. I can provide you some samples

Posted by vinaynayak on 22-Sep-2015 09:14

Irfan, Thanks for the suggestion. So invoke cURL from Progress code?

I am interested in either or both samples you have to offer.

Posted by Irfan on 22-Sep-2015 10:21

cURL is a command line utility. You can run it from ABL from OS-COMMAND or which ever way you prefer.

But if you are using ABL ,then you can consider using ABL HTTP Client(If your OE version is 11.5)

I have attached the documentation for ABL HTTP Classes in this post

This thread is closed