Log In  

Has anyone figured out how to make a http GET request in Picotron? I saw it listed in the roadmap for the 3/14 release but couldn't find a function in the list provided by NuSan here.

Thanks! :D

P#143382 2024-03-16 22:11 ( Edited 2024-03-16 23:02)

2

Try looking into fetch

Digging into SLATE i found this

local help = fetch("https://raw.githubusercontent.com/scrapSavage/SLATE/main/help.txt")
store("help.txt",help,{})
P#143404 2024-03-17 00:21 ( Edited 2024-03-17 00:22)
1

Ah yes, SLATE uses fetch which returns a raw result of whatever http address you put it (fetch is also used to load files). I'm using a Github Raw link so that it only returns the source code I want to download but you can also get the html of websites (eg: print(fetch("https://scrapsavage.dev/"))

P#143407 2024-03-17 00:33

Excellent! Thank you both very much!!

P#143410 2024-03-17 00:43

Note that there's a couple bugs with fetch:

  1. I can reliably crash Picotron 0.1.0b when calling fetch() containing a remote URL with a query string that is 60+ characters long:
-- Works
print(fetch("https://example.com?ThisQueryIs59CharactersLongThisQueryIs59CharactersLongThisQ"))

-- Crashes Picotron
print(fetch("https://example.com?ThisQueryIs60CharactersLongThisQueryIs60CharactersLongThisQu"))

But, if there's a / immediately before the ?, it works again:

-- Works now with the /
print(fetch("https://example.com/?ThisQueryIs60CharactersLongThisQueryIs60CharactersLongThisQu"))
  1. fetch() forces remote URLs to lowercase / is case insensitive, which breaks requests to some sites (like Fandom; its URLs are case sensitive)

Can confirm it yourself with this testing API that just echos back the requested URL:

print(fetch("https://echo.free.beeceptor.com/UPPER_case"))
P#144000 2024-03-21 00:24

@scrapSavage are you having any trouble with fetching remote webpages in newer versions of Picotron? for the last 2-3 versions, it doesn't seem to work for me. If I try and fetch and print any of the example listed in this thread or any other website, I get no output..

P#145211 2024-03-31 04:53
1

You need to wrap remote fetches in coroutines in the past few versions, this helps fetches not fail for people with slow internet.

P#145230 2024-03-31 10:38 ( Edited 2024-03-31 10:39)

Got it! Thanks so much for the help!

P#145286 2024-03-31 21:02 ( Edited 2024-03-31 21:02)

[Please log in to post a comment]