Delphi XE client for Dreamfactory

Has anyone done one? I’d appreciate some help with the basics (I have a Delphi desktop app that I’d like to connect to a remote server. The server is set up - I need code in the desktop app to register users and make calls to the API).

Thanks.

Paul Smith

I’ve figured out the login and JSON download. If anyone needs it, let me know.

Paul

3 Likes

Thanks for contributing! I’m sure there are other folks who are interested in this.

Hey @paulsmith glad to hear you figured it out! We’d love for you to share it in this thread. :slight_smile:

Thanks,
@AlexBowen

Saw this by chance. Also had to deal with Delphi+DF recently. See my Gist for login https://gist.github.com/philicious/87e40356291825977f8dbb08bcc8b1fc

As you can imagine, code gets quite bloated and ugly with all this TJSONObject wrapping, so I might be doing a Delphi swagger-codegen template in some weeks so you can generate SDK from your service definitions. Which is working great for Android/iOS but in their ~30 supported languages, they do lack Delphi…(not surprising me…really dont like it :stuck_out_tongue: )

@paulsmith would you be up for doing this in a joined effort ?

1 Like

@philicious. Thanks for the link. I’m a novice at this, and I have to confess I have no idea what a swagger-code template is - although I am intrigued. Anyway, here for the cause is what I have - code to log on, and then to put the JSON response into a data table. Still have to figure out user account creation. Comments and corrections welcome. Best regards, Paul

@paulsmith so DF supports “service definitions” which are swagger.io definitions, you can easily try them via editor.swagger.io
DF also generates those in background for all non-custom service types and the “API Docs” are actually a github.com/swagger-api/swagger-ui based on those.
Swagger also has github.com/swagger-api/swagger-codegen/ which can generate an SDK for dozens of languages based on the same definitions. Basically the SDK does all the JSON parsing for you has function calls for every API endpoint. You will simply operate on language-specific objects then, e.g. a TObject, and set the attributes, then pass it into the API function.
( Go to the editor.swagger.io and click “Generate Client” if you dont wanna do it locally)
But the bummer: There is no Delphi codegen-template yet…so to leverage the swagger-codegen power for Delphi, one would need to do this github.com/swagger-api/swagger-codegen/wiki/Building-your-own-Templates

And to finally get back to your “question”: Check TRESTResponseDataSetAdapter for getting the data into a table.

For User creation, I dont have Delphi code, but some PHP snippets which should give you the idea.

(sorry for all those links not being clickable but I always see “…new users can only have 2 links in post” when saving :open_mouth: )

2 Likes

@philicious
You might think that one thing a component called TRESTResponseDatasetAdapter would do is ingest a JSON response and extrude a dataset. I spent an evening trying to make it do that, and ended up just writing the code. See the sample in my earlier post. If you know how to do it with the component, please let me know.

Thanks again.

1 Like

@paulsmith I have to admit I’m not that deep into the Delphi code here. My responsibility ends where data is received. :stuck_out_tongue: but I’ve seen the Devs use TRESTResponseDatasetAdapter and feed it with the JSON response.

Unfortunately I cant share enough of our code that would help you but I did a quick google and maybe these examples will help you get it running:

On the other hand, you dont have to use TRESTResponseDatasetAdapter at all. You could also read and use the JSON response yourself.
(Personally, I’m not a big fan of all those “magic” Delphi components anyways. I’ve seen them failing or behaving in a weird unpredictable way often enough. And they are terrible to debug :scream:)

1 Like