X11Basic icon indicating copy to clipboard operation
X11Basic copied to clipboard

Issue with OPEN when trying to retrieve json response from a public API / Incomplete documentation

Open ctzio opened this issue 2 years ago • 1 comments

There seems to be an issue when using open to retrieve information from a public API.

Calling http://worldtimeapi.org/api/timezone/Europe/Athens will produce a json string of the current time and some additional information.

However there seems to be no way to retrieve the information. The following code will produce an error

server$= "worldtimeapi.org/api/timezone/Europe"
open "UC",#2, server$,80
ERROR at line 2: Unknown Error init_sockadr
ERROR at line 2: Unknown Error OPEN

While this

server$= "worldtimeapi.org"
open "UC",#2, server$,80
print #2,"GET /api/timezone/Europe"

Will produce a

HTTP/1.1 400 Bad Request

Curl will correctly work with the API endpoints and fetch the json string. I imagine it's possible to use SYSTEM and call curl to workaround this, but it assumes that Curl will exist on the system and it's not quite as elegant as when handled by the language.

ctzio avatar Dec 29 '22 23:12 ctzio

The first of your examples cannot work because the servername must not contain the path or URL. However your second example works as expected. Why the server responds with 400 is maybe because the request was not understood. But this would be a server issue.

kollokollo avatar Mar 03 '23 08:03 kollokollo