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:

  1. Open Microsoft Visual Studio and select File > Open > Project/Solution.

  2. Browse to <User>\Documents\Thriftly Developer\CSharp\PropertyTracker and open the PropertyTracker.csproj project file.

  3. The PropertyTracker project appears expanded within the Solution Explorer sidebar. From the sidebar, select Program.cs.

Program.cs in the Solution Explorer
  1. Examine how the application’s Program.cs file is constructed. In particular, note how the application:

    • References the Thriftly.Server library. Referencing this library allows PropertyTracker to include a variety of Thriftly-related directives and metadata.

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

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

    Starting the Thriftly Server

As you’ve seen, Property Tracker 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 Program.cs 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 Solution Explorer sidebar, expand the Services folder. Then, select LocationService.cs.

  2. The LocationService.cs file opens in your Code window. Examine the service, taking particular note of the following:

    • The using Thriftly.Server 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 using Thriftly.Server directive
    • 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, 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 PublishedAttribute 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 .NET/C# service, built as you’d build any other .NET/C# 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 Visual Studio toolbar, select Build > Build Solution.

  2. Select the Start button to run the Property Tracker application.

When you run the application, two windows appear. The Property Tracker Example window contains a Stop button that allows you to stop the app after you’ve finished your testing. The Thriftly Developer window allows 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.