Can you complete this fetch js code problem?

What is the task in the fetch js code problem provided? Describe the instructions that need to be followed to solve this problem.

Task Description:

In this fetch js code problem, the task is to create a function called addPerson in the fetch-post.js file. The function needs to make a POST request to http://example.com/api/people with a specific JSON body.

Instructions:

To solve this problem, follow these instructions:

  • Create a function named addPerson in the designated fetch-post.js file.
  • In the addPerson function, construct a POST request to http://example.com/api/people with the given JSON body structure:
  • { "firstName": "Maul", "lastName": "Kimmerman" }

  • If the request is formatted correctly, you can expect the response body to have the following structure:
  • { "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" } ] }

  • From the addPerson function, return the value associated with the 'people' key.

The task in the fetch js code problem is to create a function called addPerson in the fetch-post.js file that makes a POST request to a specific URL with a predefined JSON body. The function should return the value of the 'people' key from the server's response. The provided JSON body for the POST request includes the 'firstName' field with the value of "Maul" and the 'lastName' field with the value of "Kimmerman". The expected response from the server includes an array of 'people' objects with 'id', 'firstName', and 'lastName' properties. To solve this problem, you need to create the addPerson function in the fetch-post.js file and use the fetch API to make a POST request to the specified URL with the given JSON body. After receiving the response, parse it and return the value of the 'people' key. The final answer should include the JavaScript function addPerson() that handles the POST request and extracts the 'people' data from the server's response.

← Serviceable condition ensuring safety at sea Setting a uniform sampler with shader class →