REST.RESTDemo Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample illustrates how to use the DataSnap REST components on source level.


You can find the REST Demo sample project at:


This sample consists of several examples that show how to use the REST Client Library. These examples connect to the REST–service from Discogs, Twitter, Google, or DropBox.

The user can access the examples by going through each tab of the main form. The Twitter example demonstrates how to connect to Twitter API using the OAuth1 and how you can send a tweet from your Delphi application. The use of OAuth2 is shown in Accessing Google Tasks API example.

How to Use the Sample

  1. Navigate to Start | Programs | Embarcadero RAD Studio Athens | Samples and open Object Pascal\Database\RESTDemo\RESTDemos.dproj.
  2. Press F9 or choose Run > Run.
  3. Select the Twitter tab.
  4. Register the client as an application on Twitter developer-console.
    Note: You need to sign in with your Twitter account or to create one if you don't have an account.
  5. Go back to the REST Demo application running and enter the Consumer-Key and the Consumer-Secret values.
  6. Click the Get Request-Token and Auth-Code button.
    Note: This example requires a SSL encrypted connection. You can install the SSL library and copy the libeay32.dll and the ssleay32.dll files to your system path.
  7. Enter your Twitter account information in the OAuth Web Login page opened.
  8. Transfer the six-digit verification-code manually as it cannot be copied into the clipboard.
  9. Click the Close button.
  10. Enter the verification-code to Auth-Verifier (PIN) TLabeledEdit.
  11. Click the Get Access-Token button.
  12. Type a Tweet status or click the Create tweet button.
  13. Click the Send a tweet button.


File Contains


Contains the main form.


The project itself.


Tfrm_Main is the form of the application. This form contains objects like: TTabSheet, TRESTClient, TRESTRequest, TRESTResponse, TOAuth1Authenticator, TOAuth2Authenticator and defines a set of procedures as: LoadConnectionData, OAuth2_Facebook_AccessTokenRedirect, or ResetRESTComponentsToDefaults.


  • The btn_Twitter_RequestAuthPINClick procedure transfers the Consumer-Key and the Consumer-Secret values to Twitter's request-token-endpoint and gets the Request-Token and the Request-Token-Secret values using the GetSimpleValue method of TRESTResponse. In this procedure, the Tfrm_OAuthWebForm is created to allow the user to get the authentication verifier.
  • The btn_Twitter_RequestAccessTokenClick procedure gets the authentication verifier entered by the user, makes a request to the access-token-endpoint through the AccessTokenEndpoint property of the TOAuth1Authenticator, and gets the Access-Token and the Access-Token-Secret values.
  • The btn_TwitterClick procedure sends a Twitter status using the rmPost value of the TRESTRequest method property. This procedure adds a status parameter to the Params property of TRESTRequest.


See Also