DataSnap.FireDACJSONReflect REST Server Client Sample

From Appmethod Code Examples
Jump to: navigation, search

This sample demonstrates the use of the Data.FireDACJSONReflect unit to pass FireDAC datasets and deltas between a DataSnap client and a DataSnap REST server.

Location

You can find the FireDACJSONReflect sample project at:

Description

This sample demonstrates how to build a multi-tier application with DataSnap framework.

The server and the client communicate using the HTTP protocol to exchange JSON data through a REST interface.

Server

  • The server is a DataSnap REST web application that accesses data from an InterBase database.
  • The sample adds FireDAC components to the Server Module to connect to an Interbase database.
  • The sample adds new methods in ServerMethodsUnit1 to retrieve JSON data from the underlying InterBase EMPLOYEE sample database, and to expose these server methods to the client.

Client

  • The client is a multi-device application that includes a DataSnap REST Client Module.
  • The client calls the server methods to retrieve the data from the server.
  • The client also calls a method to apply changes to the database storing and passing data through TFDMemTable components.

How to Use the Sample

  1. Navigate to Start | Programs | Appmethod 1.16 | Samples and go to Object Pascal\DataSnap\FireDACJSONReflect.
  2. Select DepartmentsClientProject.dproj and DepartmentsServerProject.dproj.
  3. Open the client and the server.

Server Project

  1. Select DepartmentServerProject.exe on the Project Manager.
  2. Run the application by clicking Run > Run Without Debugging in the IDE or by pressing Shift+Ctrl+F9.
  3. The Server's interface opens. Click Start to start the server and then minimize it.

Client Project

  1. Select DepartamentClientProject.exe on the Project Manager.
  2. Run the application by clicking Run > Run in the IDE or by pressing F9.
  3. The Client application enables you to test the server method classes.
    • Click Get Departments to display a list of department names and numbers.
    • Click on a department to see department details and employees.
    • Modify a value in the department details and/or employee and then click Apply Updates to send changes to the server.

Files

The files used by this sample are:

Server Files

File Contains

WebModuleUnit1.pas/dfm

The DataSnap Server Components.

ServerMethodsUnit1.pas/dfm

The Server module with the FireDAC components.

DepartmentsServerProject.dproj

The project itself.

DepartmentsServerFormU.pas/dfm

The Server form.

Client Files

File Contains

DepartmentsClientProject.dproj

The project itself.

DepartmentClientFormU.pas/fmx

The main form that is the user interface for the DataSnap Client application.

ClientModuleUnit2.pas/dfm

The module with the TDSRestConnection component.

ClientClassesUnit2.pas

The client classes from the server generated with the TDSRestConnection component.

Uses

See Also