Reviewing the PropertyTracker Sample App and APIs

PropertyTracker is a sample Windows application included in your Thriftly Developer install. PropertyTracker keeps track of a user’s purchases (including products purchased, the locations where purchases took place, purchase prices, etc.) by connecting to a Microsoft SQL LocalDB database.

PropertyTracker also contains several example Thriftly APIs, which you can use as a model when creating APIs of your own. We suggest you thoroughly review the PropertyTracker app, and the Thriftly-related code contained within, to learn how Thriftly APIs are created and defined within an application.

Reviewing the Sample Application

To review the PropertyTracker application:

  1. Open DataFlex Studio and select File > Open Workspace.

  2. Browse to <User>\Documents\Thriftly Developer\DataFlex\PropertyTracker and open Mertech Example Application.

  3. If necessary (depending on your version of DataFlex Studio), follow the prompts that appear and select Finish to import the project. The PropertyTracker folder appears as the project’s root directory.

  4. From the DataFlex Studio toolbar, select File > Open File(s). When the Open File(s) window appears, select and open PTThriftly. PTThriftly.src appears in the main DataFlex Studio workspace.

  5. Examine how the application’s .src file is constructed. In particular, note how the application:

    • Imports the Thriftly library. Importing this library allows PropertyTracker to include a variety of Thriftly-related directives and metadata.

    The Use Thriftly.pkg directive
    • Instantiates a Thriftly Server object that includes three services.

    A Thriftly Server object and services
    • Starts the Thriftly Server application.

    Starting the Thriftly Server

As you’ve seen, PropertyTracker includes three services, LocationService, ItemService, and ProductDirectoryService.

The services included in our sample PropertyTracker application

Each of these services comprises a separate Thriftly API, allowing outside users and applications to make API calls to functions contained within the PropertyTracker application. Now that you’ve seen how these services are included in the application’s .src file, let’s examine one of the services themselves.

Reviewing an Example Service

Let’s take a look at the LocationService service:

  1. From the Code Explorer sidebar, expand the oThriftly sub-folder. Then, right-click LocationService.pkg and select Open <LocationService.pkg>.

The LocationService in the Code Explorer sidebar
  1. LocationService.pkg opens in the main DataFlex Studio workspace. Examine the service, taking particular note of the following:

    • The Object oLocationService is a cThriftlyService directive. When you publish your service to the Thriftly Server as an API, the server references this directive to confirm the service is meant to be published.

    The Object oLocationService is a cThriftlyService directive
    • The {Published = True} attribute. This attribute tells the Thriftly Server which functions users can call when they access your API. In LocationService, you’ll see the {Published = True} attribute above the getLocation, searchLocations, addEditLocation, and deleteLocation functions. Users can access those functions when they interact with our LocationService Thriftly API. Note that if our service included other functions that did not include the {Published = True} attribute, users would not be able to call those functions when making requests of our API.

    The {Published = True} attribute

The service itself contains a lot more code, but the two pieces we mentioned above are the pieces that define this service as a Thriftly API. Otherwise, LocationService is simply a normal DataFlex service, built as you’d build any other DataFlex service you’d include within an application.

If you open and examine the ItemService and ProductDirectoryService services, you’ll find they’re constructed the same way. Now that you understand how the services that become Thriftly APIs are constructed, let’s run the PropertyTracker application and examine exactly how application services translate into Thriftly APIs.

Running the Sample Application and APIs

Let’s compile and run PropertyTracker, so we can access our services as Thriftly APIs.

  1. From the DataFlex Studio toolbar, switch your project from Property Tracker.src to PTThriftly.src. Then, select the Run button.

The PTThriftly.src project and DataFlex Studio Run button

When you run the application, the Thriftly Developer window appears to allow you to start configuring and testing your APIs.

To test out the PropertyTracker APIs using Thriftly’s API testing interface, click over to the Testing Your Thriftly API section. After you’ve finished playing around with the PropertyTracker APIs, you’ll be ready to create some basic Thriftly APIs of your own, using the instructions in the next section.