Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 14 in printed book and digital formats -- plus a one-year subscription so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 14.5 ('Keyboard Shortcuts')
Instant purchase and download via GumRoad!

COLUMN

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):

http://demos.xojo.com/EEWS/index.cgi/api/
http://demos.xojo.com/EEWS/index.cgi/api/GetAllCustomers

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 HTTPsocket/HTTPsecuresocket without 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_project in the Harness Projects folder. Then copy the REST Reasources folder to your application (using copy/paste). The REST Harness.xojo_project is 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 GetCustomer and GetCustomerList. Looking at GetCustomerList, it has one property (ReturnGetAllCustomers - see codelisting 3) and two events (GetRESTType, GetURLPattern—see code listings 1 and 2).

...End of Excerpt. Please purchase the magazine to read the full article.