Project

General

Profile

Accessing Restful API

Added by Bert Cuypers over 4 years ago

Hi all,

Which is the best way in Wt to access a (non-Wt) Restful API? Should JS be used, or are there other methods?

Thanks in advance!

Best regards,

Bert


Replies (4)

RE: Accessing Restful API - Added by Roel Standaert over 4 years ago

Usually we're doing the communication with APIs server side, using Wt::Http::Client. It's a fairly simple one that suffices for many uses. Other C HTTP client libraries exist if Wt's doesn't suffice though.

RE: Accessing Restful API - Added by Bert Cuypers over 4 years ago

Hi Roel,

This is exactly what I needed! Thanks a lot!

Best regards,

Bert

RE: Accessing Restful API - Added by Bert Cuypers over 4 years ago

Hi Roel,

Is it also possible to use this Wt::Http::Client without any WApplication object existing?

I'd like to have communication with the APIs at night when there are no users connected with my app...

Thanks in advance

Best regards,

Bert

RE: Accessing Restful API - Added by Roel Standaert over 4 years ago

Yes. All the HTTP client needs is an io_service. If you create one with the default constructor inside of a WApplication it will automatically use the io_service of the WServer (and post all of its events to that WApplication).

Use this constructor with an io_service for which at least one thread is running run() to create a Client outside of a WApplication: https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1Http_1_1Client.html#a966378bd63f2babf2f8d2beb2783e45e.

    (1-4/4)