If you’re looking for a cross-platform application that demonstrates how to do an asynchronous REST API call, look no further than the Async REST Demo. This powerful little app is built in Delphi using a single code base and single UI, making it truly cross-platform. And because it’s asynchronous, you can be sure that your results are always up-to-date. Supports Android, iOS, macOS, Windows, and Linux.

Download the full cross-platform Hello World source code on Github.

This demo is part of over 100 cross-platform demos with everything from camera demos to emoji demos and painting demos.

What does asynchronous mean in software development?

In software development, asynchronous refers to a type of communication between two or more components where each component can proceed independently of the others. This contrasts with synchronous communication, where each component must wait for a response from the others before it can continue. Asynchronous communication often occurs in event-driven systems, where each component can respond to events as they occur without waiting for input from the other components. This type of communication can improve performance and responsiveness by reducing or eliminating bottlenecks. In addition, asynchronous communication can provide a more robust and scalable system by allowing components to handle different workloads independently.

Screenshot

What is the source code of the demo?

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, REST.Types,
  FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param,
  FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf,
  System.Rtti, FMX.Grid.Style, Data.Bind.EngExt, Fmx.Bind.DBEngExt,
  Fmx.Bind.Grid, System.Bindings.Outputs, Fmx.Bind.Editors, FMX.StdCtrls,
  Data.Bind.Components, Data.Bind.Grid, Data.Bind.DBScope, FMX.ScrollBox,
  FMX.Grid, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
  REST.Response.Adapter, REST.Client, Data.Bind.ObjectScope, FMX.Effects,
  FMX.Controls.Presentation, FMX.Memo, FireDAC.Stan.StorageJSON, FMX.Memo.Types;

type
  TForm1 = class(TForm)
    MaterialOxfordBlueSB: TStyleBook;
    ToolBar1: TToolBar;
    ShadowEffect4: TShadowEffect;
    Label1: TLabel;
    RESTClient1: TRESTClient;
    RESTRequest1: TRESTRequest;
    RESTResponse1: TRESTResponse;
    RESTResponseDataSetAdapter1: TRESTResponseDataSetAdapter;
    FDMemTable1: TFDMemTable;
    Button1: TButton;
    Memo1: TMemo;
    FDStanStorageJSONLink1: TFDStanStorageJSONLink;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Clear;

  RESTRequest1.ExecuteAsync(
    procedure
      begin
        Label1.Text := 'Complete!';
        Memo1.Lines.Append('Userid: ' + FDMemTable1.FieldByName('Userid').AsString);
        Memo1.Lines.Append('id: ' + FDMemTable1.FieldByName('id').AsString);
        Memo1.Lines.Append('title: ' + FDMemTable1.FieldByName('title').AsWideString);
        Memo1.Lines.Append('body: ' + FDMemTable1.FieldByName('body').AsWideString);
      end,
    True,
    True,
    procedure (Sender: TObject)
      begin
        Label1.Text := 'Error!';
      end);
end;

end.

Ready to learn how to program cross-platform apps like this?

Sign up for the Coding Boot Camp 2022 to learn to program. Topics include: Games, JavaScript, Web, Python, SQL, Databases, iOS, MacOS, Android, Mobile, Linux, Windows, Desktop, Server, and Arduino.


Reduzieren Sie die Entwicklungszeit und kommen Sie mit RAD Studio, Delphi oder C ++ Builder schneller auf den Markt.
Design. Code. Kompilieren. Bereitstellen.
Kostenlos testen   Upgrade heute

   Kostenlose Delphi Community Edition   Kostenlose C ++ Builder Community Edition