To communicate with a server, you can use one of the several available REST API's. When you send a request to a server, it sends you back a structured response expressed in JSON or XML. You then need to analyze this response to take further actions.
These REST parsers modules are very fast and very flexible in analyzing structured responses in JSON or XML, as they are based on one pass parsers. They return attributed token results instead of using intermediate structures such as a DOM tree. There are three well documented and portable Delphi Pascal modules, which were also used for the server communication in this Webshop application:
- The JSON module offers functions to analyze a JSON response.
- The XML module offers functions to analyze an XML reponse.
- The Base64 module converts a base64 string into a byte stream or a decoded string and vice versa. Servers convert binary data, such as pictures or files to a base 64 string and return it as part of a JSON or XML response.
Demonstration programs in VCL (Windows only) and Firemonkey (Windows, MacOS, iOS and Android) illustrate how to use the functions in these modules. The picture below is a screenshot of the demonstration program showing how to handle different kinds of responses, either in JSON or in XML. They can either return a response as a list of tokens or directly converts a response into objects. In the example below, the response is a list of three objects, wjich are either returned as a list of tokens or directly converted into three objects, ready to display (in the lower right part of the screenshot):