Jump to content
RCrandall

Getting up to speed with TRestClient and the other components

Recommended Posts

I'm new to REST and trying to communicate with web services generally.  I have lots of experience with other areas of coding in Delphi but no background whatever for web services.  I now have a task to get a web service client going and have done a complete face plant.  Often I used to be able to get a new library of components and work out from the docs and the properties/methods of the components what needed to be done.  It required a bit of patience and Googling but it worked.  This isn't working this time - the new task is just a whole order of complexity above what I have time for now.

 

By any chance, has anyone used the standard TRestClient / TRestRequest / TRestResponse components in real life?  Can you possibly point me to a good write-up and/or working code that illustrates its use?  I feel like I have looked everywhere and come up with just fragments, most of which don't seem to work.

 

In the alternative, if anyone knows their way around this area and had the time to help me directly, I could come up with some money to make it happen.  I have a clear requirement I'm trying to satisfy and I've got a test program that connects to the web service (or at least appears to) and I can send and parse the results of GET requests successfully.  I'm flummoxed trying to get the first POST request to work though.  I appear not to have set up encoding correctly or some other gotcha because of my lack of background knowledge.  My specific stopper right now is a "403, Forbidden: Content type 'multipart\/form-data' is not supported."  I'm stuck on that and need help!

 

Thanks in advance to anyone with suggestions or can help in some way, cheers, Rob Crandall

Share this post


Link to post
24 minutes ago, RCrandall said:

By any chance, has anyone used the standard TRestClient / TRestRequest / TRestResponse components in real life?

I have done that for quite a couple of web services. The critical information is a description of the web service. Regarding your specific 403 problem it is necessary to find out how the data is expected by the service. Do you have some reference for that at hand?

  • Like 1

Share this post


Link to post

Yes, I believe I do have that info.  The people at the server end are part of a related company and trying to help but are too busy to really do much.  They pointed me to their internal dev wiki that has brief info, and then something called Swagger that I believe uses WSDL to show all the nitty-gritty details complete with CURL examples of usage.  This took a while to parse out but I am able to get results in Swagger and the equivalent code, as near as I can make it, fails in Delphi.  It could be something super simple or something super complex - I just cannot tell.   The thing is, this is a commercial entity and I can't just share this info to the world.

 

I'm using 10.4.2 under Windows 10 btw.

 

This is a new experience for me.  I'm wondering now if I should try out an online service-for-hire place for Delphi programmers.   Does this sound like a good idea or is this a well-travelled route to the bad place?  I just don't know.  

 

Thanks, Rob

Share this post


Link to post

There are several free and opensource REST libraries available so you don't have to start from scratch. I would recommend

  • DMVCFramework --  a popular and powerful framework for web solution in Delphi. Supports RESTful and JSON-RPC APIs development.
  • WiRL -- RESTful Library for Delphi.
  • mORMot -- Synopse mORMot ORM/SOA/MVC framework

See example applications to a specific framework.

Share this post


Link to post
7 minutes ago, RCrandall said:

The thing is, this is a commercial entity and I can't just share this info to the world.

Well, without the information about how the data is expected, you will have hard time to find advice here. The swagger description and example of the endpoint you are trying to reach with POST would be sufficient. We don't need access to the whole documentation or even the web service.

  • Like 1

Share this post


Link to post
2 hours ago, Kryvich said:

There are several free and opensource REST libraries available so you don't have to start from scratch. I would recommend

  • DMVCFramework --  a popular and powerful framework for web solution in Delphi. Supports RESTful and JSON-RPC APIs development.
  • WiRL -- RESTful Library for Delphi.
  • mORMot -- Synopse mORMot ORM/SOA/MVC framework

See example applications to a specific framework.

Thank you, I will check this out!  I'm hoping that a combination of helpful sample code will put me on the right track!  This gives me another three to play with.

 

Rob C

Share this post


Link to post
20 hours ago, Kryvich said:

I would recommend

Don't these libs implement server side while OP needs client?

General hint: if you have some REST soft working and some not, get the dumps of their requests and compare. That will be much more useful than any guessing. curl can dump all traffic with some options but I'm not sure about Delphi client... still, you can use Wireshark (traffic sniffer) for this or some special proxy.

Share this post


Link to post
2 hours ago, Fr0sT.Brutal said:

Don't these libs implement server side while OP needs client?

General hint: if you have some REST soft working and some not, get the dumps of their requests and compare. That will be much more useful than any guessing. curl can dump all traffic with some options but I'm not sure about Delphi client... still, you can use Wireshark (traffic sniffer) for this or some special proxy.

I too am a big fan of visualizing the raw data and I have been trying to do just this.  Fishing that info out of the components is harder than it looks when they are wrappers for OS functions but something like Wireshark could be the real answer.  Thanks for reminding me about it.  I've never used it but it might be time to get acquainted with it!

 

Thanks, Rob C

 

P.S.  I love your list of Delphi stuff btw and visit your website regularly to see what is new.

Share this post


Link to post

Hello everyone.  I'm happy to report that Mr. Uwe Rabbe got me going on this.   I shared some further details with him and he was able to come up with code that worked.  Darned if I know what is different that caused the problem, but heck, it works, and from this solid foundation I can now work outwards and learn the rest and perhaps even identify what my original problem traced back to.

 

Thanks Uwe!  I genuflect in your general direction.

 

Regards, Rob Crandall

Share this post


Link to post

@RCrandall You can put some likes for his answers in this thread, and thus increase his already high reputation on Delphi Praxis. 😉

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×