Data file from http.request

I read a file with http.request and the file, which is a row of numbers, is in the variable called data.
Now I want to loop throug the rows and save every single row in a new array variable, so I can have acces to each independantly.
I need to know the number of rows in the data and to pick every row and then loop, but how is that practical possible ?
Re Peter

Ps. I know of course how to make a loop. It is the data variable that I cannot understand.

I think that unpack() might be helpful for you.

If you have the body of the response then you have one long string with newlines in it. You have to split it manually into a list of separate lines.

I ended up doing it manually, so it is fixed now.
Unpack() may come in handy an other time. Thanks for the tip.
Learning all the time… :wink:

My question is HOW do I get access to the data?
From the Code Referenceworks: (naturally replacing url by a REAL url)

function setup()
 testData = nil

function getDidData(data staus, headers)
 print(status .. " : " .. data)

but there is something missing:
in getDidData one probably has to add:
testData = data
And how do I wait for the answer ??

Yes, when the response arrives the callback will be executed and you have to remember everything. Like this:

testData = nil
responseError = false

. . .  make a request . . .

function didGetData(data, status, headers)
    if status == 200 then
        testData = data
        responseError = true

function waitForData()
    if testData ~= nil then
        -- Data is here, do something with it
    if responseError then
        -- Bad response from http.request

Also, make sure to use 3 tilde characters at the start and end of code blocks in this forum, use the Preview button when in doubt.

And make sure that you don’t mix up names like “didGetData” and “getDidData” in your live code. Sometimes, a wrong name might go unnoticed.

CodeSlinger, thanks for clarifying this for me
Couldn’t such an example not in the help of http.request, or is so clear how to manage?