REST.SurfSpotFinder Sample (C++)

From RAD Studio Code Examples
Jump to: navigation, search

This sample shows how to integrate and use REST services in your application by using the Spitcast API in a C++ application.

Location

You can find the SurfSpotFinderApp sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and then navigate to:
    • CPP\Multi-Device Samples\Cloud\SurfSpot Finder
  • Subversion Repository:
    • You can find C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

The application connects to the REST service from Spitcast to retrieve the list of Surf spots (sea locations for surfing). The application creates a main form that has a TMultiView component. The TMultiView component contains a list of Surf spots. Select a Surf spot from the SurfSpot finder list in order to display its location info: Location, Longitude and County. Each location info is displayed on an item of a TListBox. The sample also uses a TPanel with a TWebBrowser component for displaying the location on google maps.

Note: Public distribution of Spitcast API content must acknowledge Spitcast as the content source, and provide a link to spitcast.com. The Spitcast API is available for non-commercial use. Commercial use is possible by prior arrangement.

How to Use the Sample

  1. Navigate to the location given above and open CppSurfSpotApp.cbproj.
  2. Select the target platform.
  3. Press F9 or choose Run > Run.

Files

File Contains

CppSurfSpotApp.cbproj
CppSurfSpotApp.cpp

The project itself.

MainUnit.h
MainUnit.cpp
MainUnit.fmx

The main form.

Classes

TForm4, the form class, implements the main visual component of the application. It contains a TMultiView component and a TPanel with a TWebBrowser component for displaying the location on a map. It also contains the following components: TRESTClient, TRESTResponse, TRESTRequest, and TRESTResponseDataSetAdapter.

Implementation

  • For the TMultiView1 component, in the Object Inspector, set the TargetControl property to Panel1 and the MasterButton property to backbtn.
  • For the RESTClient1 component, in the Object Inspector set the BaseURL property to http://api.spitcast.com.
  • For the RESTRequest1 component, in the Object Inspector set the following properties:
    • The Client property to RESTClient1.
    • The Response property to RESTResponse1.
    • The Resource property to api/spot/all.
    • The Method property to rmGET.
    • Right-click the RESTRequest1 component and click Execute.
  • For the RESTResponseDataSetAdapter component, in the Object Inspector set the following properties:
    • The Response property to RESTResponse1.
    • The Dataset property to FDMemTable1.
  • Right-click the FDMemTable and select Fields Editor.
    • Right-click the Fields Editor, select Add Fields and the fields county_name, latitude, longitude, spot_id, and spot_name.
  • For the TMultiView1 component, visually bind the Surf Spots list from the Spitcats API call.

Uses

See Also

Samples