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 MariaDB 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:
Open Delphi RAD Studio and select File > Open Project.
<User>\Documents\Thriftly Developer\Delphi\PropertyTrackerand open the PropertyTracker project file.
The PropertyTracker project appears within the Project Manager sidebar, and PropertyTracker.exe appears within the main RAD Studio workspace.
Examine how the application’s .exe file is constructed. In particular, note how the application:
References the ThriftlyServer library. Referencing this library allows PropertyTracker to include a variety of Thriftly-related directives and metadata.
Instantiates a Thriftly Server object.
Calls the three services that will become Thriftly APIs.
Starts the Thriftly Server.
As you’ve seen, PropertyTracker includes three services, LocationService, ItemService, and ProductDirectoryService.
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 .dpr file, let’s examine one of the services themselves.
Reviewing an Example Service¶
Let’s take a look at the LocationService service:
From the Project Manager sidebar, select and open LocationService.pas.
The LocationService.pas file opens in the RAD Studio workspace. Examine the service, taking particular note of the following:
The uses Attributes directive. This directive allows a service to reference the [PublishedAttribute] attribute, which we’ll explain next.
The [PublishedAttribute] attribute. This attribute tells the Thriftly Server which functions users can call when they access your API. In LocationService, you’ll see the [PublishedAttribute] 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 [PublishedAttribute], users would not be able to call those functions when making requests of our API.
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 Delphi service, built as you’d build any other Delphi 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¶
Let’s compile and run PropertyTracker, so we can access our services as Thriftly APIs. To do so:
From the RAD Studio toolbar, select the 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.