06 - Get one item
In this module, we'll write a GET request that grabs a single item from the database for a specific user.
CODE
Add the following method to the 03-auth-test.js
file:
Analysis
We get the
postIdNumber
provided in thegetNumber
field. Because we are making an authenticated request, thisid
has to exist in the database, as well as match theuser.id
from the database for the user that you are using currently logged in as.We pass the
postIdNumber
into the url with a template literal.We target an element called
getItemValue
. It's alabel
tag.We set the value of the label to the value of
response.authtestdata
. This means that the data will be populated in the label when the DOM loads.
Test
Go ahead and run the app.
Click the
Get Single Item
button after putting in theid
from the previous module.You should see the following:
Notice that we have pulled the single item from the server. In this case, the item has the id of
10
.Not only did we print to the console, we added the data pulled from the server to the DOM in the
<label>
element on step 11 (GET Single Item).
Last updated