[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: call WebApi requiring API token authorisation


On 1/19/26 6:16 PM, KKing wrote:
call WebApi requiring API token authorisation

What's the best way to code calling a WebApi requiring an API "BEARER" token embedded in a header?

A quick google initially suggested using Curl but on
     Debian 12 bookworm
     Gambas 3.18.0 from the Debian repository for above
     installed gambas3-gb-net-curl from Debian repository
     Start new command line project
     add gb.net.curl component
     Dim myCurl as Curl
etc ...

but F8 fails on first line with
     Class 'Curl' is not creatable (Main:5)

On same unit, I can from terminal run Curl command with parameters and all works fine.

Is there another component or step to allow this to work in Gambas?

or

should I be using httpclient now?

If the latter is there good example to follow?

K

Just use HttpClient. It uses Curl "under the hood".

You can pass custom headers as a string array argument to both the .Get and .Post methods. For example:
HttpClient.Get(["BEARER=gobbletygook"])


--
Lee

--- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ----
--- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----


Follow-Ups:
Re: call WebApi requiring API token authorisationOlivierCruilles <olivier.cruilles@xxxxxxxx>
References:
call WebApi requiring API token authorisationKKing <kicking177@xxxxxxxxx>