Question
Modify the code below to complete the below tasks: // require in your prefered module/library to make http requests (superagent, axios, etc) const websites =
Modify the code below to complete the below tasks:
// require in your prefered module/library to make http requests (superagent, axios, etc)
const websites = { dummyjson: { name: 'Dummy JSON', url: 'https://dummyjson.com/products/1' }, spotify: { name: 'Spotify', url: 'http://www.spotify.com/us/' }, nasa: { name: 'NASA', url: 'https://www.nasa.gov/error/' }, unknown: { name: 'Unknown', url: null } };
// // # 2 - Write the requestPromise() function which uses your http request module
// // # 3 - Invoke the requestPromise() using then/catch for each websites object above
// // # 4 - Write the requestWrapper() function which interacts with the requestPromise() function
// // # 5 - Invoke the requestWrapper() for each websites object above
#Q1 - package.json (5 points)
Create a package.json This package.json should contain - name, author, description, entry, and dependencies
#Q2 - Writing a Promise using an http request library (20 points)
Write a function called requestPromise() This functions accepts two arguments - a url and a callee The url should be passed in using the provided websites object The callee should be a string which is either 'promise' or 'async/await' - depending on which type of function invoked the requestPromise() This functions uses superagent, axios, (or preferred http request lib) to make a request to each url This function has simple timer to time the duration in milliseconds of a HTTP request The timer starts before the HTTP request to the given url The timer ends after the response comes back from the given url The duration should be calculated using start and end. HINT: Review Mozilla Docs for use of Date.now() This function returns a Promise When there is a url and the response back is a success - resolve with an object that includes the url, duration, status code, content-type, callee When there is a no url or the response back is a failure/error - reject with an object that includes the url, status code, callee
#Q3 - Using a Promise with then/catch (5 points)
Invoke the requestPromise() for every website in the object - passing in the proper arguments for each companies url and callee Use .then() and .catch() properly to log the responses to the console DO NOT use Promise.all or looping
#Q4 - Writing an Async/Await Wrapper (15 points)
Write a function called requestWrapper() This functions accepts two arguments - a url and a callee The url should be passed in using the website object The callee shoul be a string which is either 'promise' or 'async/await' - depending on which type of function invoked the requestPromise() This function uses async/await syntax to properly interact with requestPromise() This function should properly to log the success or error responses to the console #5 - Using the Async/Await Wrapper (5 points)
Invoke the requestWrapper() for every website in the object - passing in the proper arguments for each companies url and callee DO NOT use any looping EXAMPLE SUCCESS:
{ url: 'http://www.spotify.com/us/', duration: 325, status: 200, content: 'text/html; charset=utf-8', callee: 'async/await' }
EXAMPLE FAILURE:
{ url: 'https://www.nasa.gov/error/', status: 404, callee: 'async/await' }
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