Tumgik
delphiuser0258-blog · 7 years
Text
Using Delphi Parse API
Given Parse was retired earlier this year, does it make sense to keep the Parse components in Delphi and how can you still use them?
The Parse web site (owned by Facebook) was retired earlier this year. This was a fairly popular BaaS (backend as a service) provider for mobile applications, but something you could use also from desktop apps. Delphi (and also C++Builder, btw) has included ready-to-use components for interfacing Parse APIs for quite some time. It was very easy to set up an account on the system and create an app. But the hosting was discontinued, and now what?
Additional Parse Hosting and the Delphi ParseProvider Component
While stopping the Parse web site, Facebook did you positive thing: they made the entire Parse server open source. So what happened is that many cloud hosting providers took that code and created compatible hosting services. By hosting the a fully API-compatible version of the Parse server, these providers made it possible to migrate client applications that were using parse with almost no effort.
There was one additional issue to use these additional providers from Delphi. Given Parse applications were hosted on parse.com, the main domain name was hard-coded in our component. Now in Delphi Tokyo Release 1 (or 10.2.1) we have added a class helper that lets you easily change the URL provider. As you can read at https://quality.embarcadero.com/browse/RSP-13608 all you need to do is add the line:
ParseProvider1.BaseURL := '...';
In a future release, this will become a property of the component, but to preserve compatibility it was added as a runtime only feature for Tokyo updates.
An Actual Example
To check this does really work I did the following. First I went to one of the Parse server providers that offers a limited free account, https://www.back4app.com/. By entering my credentials, in a minute I could create a test app and manually enter a user on their web console. The console configuration listed all of the parameters needed to connect.
Second I create a VCL forms application, with a ParseProvider component, a BackendUsers component, a button and a memo. In the ParseProvider I copied the various required IDs:
object ParseProvider1: TParseProvider  ApplicationID = 'esSv_______Whi'  RestApiKey = 'mxBY______Wl6'  MasterKey = 'kxW_____DHl' end
The BackendUsers component only configuration is the connection to the provider (which should be automatic). Third step I wrote the following code to refer to the proper URL and get the list of users:
procedure TForm12.FormCreate(Sender: TObject); begin  ParseProvider1.BaseURL := 'https://parseapi.back4app.com/'; end; procedure TForm12.Button1Click(Sender: TObject); var  aJSONArray: TJSOnArray; begin  aJSONArray := TJSOnArray.Create;  try    BackendUsers1.Users.QueryUsers([''], aJSOnArray);    Memo1.Lines.Add (aJSOnArray.ToString);  finally    aJSONArray.Free;  end; end;
0 notes