Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you complete this code problem? INSTRUCTIONS: Create a function called addPerson in the fetch-post.js file. Inside the function, make a POST request to http://example.com/api/people
Can you complete this code problem?
INSTRUCTIONS:
Create a function called addPerson in the fetch-post.js file.
Inside the function, make a POST request to http://example.com/api/people with the following JSON body:
{ "firstName": "Maul", "lastName": "Kimmerman" }
If you format your request properly, you can expect the body of the response to be:
{ "people": [ { "id": 1, "lastName": "Zimmerman", "firstName": "Paul" }, { "id": 2, "lastName": "Yimmerman", "firstName": "Raul" }, { "id": 3, "lastName": "Limmerman", "firstName": "Caul" }, { "id": 9, "lastName": "Kimmerman", "firstName": "Maul" }, ] }
Return the value of the people key from the addPerson function.
Your objective is to implement the code in fetch-post.js file. Use fetch to make a POST request with a JSON body and return a specific value from the response JSON body.
CODE:
if (!fetch) { | |
var fetch = require('./test/node-fetch')(1); | |
} | |
/** | |
* Do not change code above this line. | |
* See README.md for instructions | |
******************************************************************************/ | |
// Your code here | |
/******************************************************************************* | |
* Do not change code below this line. | |
*/ | |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started