REST Classes For Xojo
Open Source code for Xojo
Issue: 14.5 (September/October 2016)
Author: Scott Boss
Author Bio: Scott Boss is the founder of Nocturnal Coding Monkeys, Llc, who specialize in writing custom software. Scott has been a developer, system administrator, storage engineer, consultant, and architect to businesses from startup to global 100.
Article Description: No description available.
Article Length (in bytes): 6,887
Starting Page Number: 100
Article Number: 14511
Related Web Link(s):
Excerpt of article text...
This issue we will be looking at REST Classes For Xojo (https://github.com/advancedpricing/Xojo-Rest-Classes). At the time of writing this column, it was at version 1.2. Kem Tekinay of Advanced Medical Pricing Solutions wrote the module to give us an easy way to use REST APIs. These classes don't generate or provide REST APIs (there are other classes for that like Luna), but consume the APIs. Before looking at this set of classes, I have always rolled my own methods to use the REST APIs. If you are familiar with HTTP you can roll your own with
HTTPsecuresocketwithout a problem. The problem with rolling your own is you have to deal with all the various outcomes, including the server isn't responsive, various HTTP error codes, bad parameters, and much more.
Note: I have borrowed source code from the example project that comes with the REST classes. I have made a few tweaks to the code listings to make it easier to read or more understandable for the readers.
Using the REST classes, you create a new object and fill in a few parameters, and event handlers for that specific API. Then you just use that object. The REST classes handle all the heavy lifting under the hood for you. To get started, open the
REST Harness.xojo_projectin the
Harness Projectsfolder. Then copy the
REST Reasourcesfolder to your application (using copy/paste). The
REST Harness.xojo_projectis an example program that uses the REST classes (see Figure 1). There are three APIs that it uses, SQL Formater, Cats, and Eddie's Electronics (see Figure 2). Many of us are familiar with Eddie's Electronics as it is an example application from Xojo. Each of the APIs are a little different in their use and their responses. Looking at their example code makes adapting the REST classes for your API fairly easy.
Looking at the Eddie's Electronics example, there are two classes that use RESTMessage_MTC as their super (this is how you use the REST classes). They are
GetCustomerList. Looking at
GetCustomerList, it has one property (
ReturnGetAllCustomers- see codelisting 3) and two events (
GetURLPattern—see code listings 1 and 2).
...End of Excerpt. Please purchase the magazine to read the full article.