Understanding a tutorial: Using axios.get()
I'm following a tutorial that uses Express JS to create a server and integrates it with some 'static' resources (html, css, js).. showing how app.get(), app.post() work with a form etc (pic 1 & 2)
There are 2 'versions' of the form that the tutorial goes over. One of them, (the index.html), links the form to the server, in app.js, with a method = POST. (pic 3)
There, we're using a require() to get a people array out of a local file (data.js), and in our app.post using that info to test against the user's form input. (pic 1)
The second version of the form (in javascript.html), links the form to javascript (same-page script tags). This is the one I'm confused about.
Here, he uses an axios library and axios.get().. in order to somehow also grab that same people array from the same local data.js file, and then display all of the 'people' array names on the page, in a div container called "result".
The part I don't understand is the const { data } = await axios.get('/api/people')
"/api/people", in the app.js, was the URL we'd set to display already gotten data (the "people" array).
But here, in this javascript, at no point yet have we 'already gotten' that people array data.
I can't tell what the axios.get(), const { data } = await axios.get('/api/people') , is doing. Is it going to the app.js-setup URL in order to retrieve the 'people' data (as opposed to getting it from the local folder itself)?
There are 2 'versions' of the form that the tutorial goes over. One of them, (the index.html), links the form to the server, in app.js, with a method = POST. (pic 3)
There, we're using a require() to get a people array out of a local file (data.js), and in our app.post using that info to test against the user's form input. (pic 1)
The second version of the form (in javascript.html), links the form to javascript (same-page script tags). This is the one I'm confused about.
Here, he uses an axios library and axios.get().. in order to somehow also grab that same people array from the same local data.js file, and then display all of the 'people' array names on the page, in a div container called "result".
The part I don't understand is the const { data } = await axios.get('/api/people')
"/api/people", in the app.js, was the URL we'd set to display already gotten data (the "people" array).
But here, in this javascript, at no point yet have we 'already gotten' that people array data.
I can't tell what the axios.get(), const { data } = await axios.get('/api/people') , is doing. Is it going to the app.js-setup URL in order to retrieve the 'people' data (as opposed to getting it from the local folder itself)?






