Request Header Parser Microservice

I’m facing some challenges with passing the next 3 tests in this problem, and I feel a bit stuck at the moment. I’m drawing a blank and finding it difficult to figure out the solutions. The absence of hints has made these problems more challenging for me. Any assistance you can provide would be greatly appreciated. Thank you for your help!

Side Note: I know I don’t need to extract whoami parameter from request, I am just confused

// API endpoint with whoami parameter 
app.get('/api/whoami', (req, res) => {
  // Extract whoami parameter from request 
  const whoamiParam = req.params.whoami; 
  // Initialize variable to hold whoami object
  let whoamiObject; 
  //
})

Update, still confused but I think this is a better start:

// API endpoint with whoami parameter 
app.get('/api/whoami', (req, res) => {
  // Initialize variable to hold ip address and language and software
  const ipAddress = req.ip; 
  const language = req.header[`accept-language`]; 
  const software = req.header[`user-agent`]; 

  res.json({ipAddress: , language: , software: }); 
  

})

Suprised I actually passed, I’m sure there’s mutiple ways to solve this, is this way bad? I had to get familiar with using req.header, you can basically console log it and see everything a “client” sent then put the header-name in brackets to access it. Then just run all the variables you created through res.json and then it’s solved. This one actually wasn’t too bad

// API endpoint with whoami parameter 
app.get('/api/whoami', (req, res) => {
  // Initialize variable to hold ip address and language and software
  const ipAddress = req.ip; 
  const language = req.header[`accept-language`]; 
  const software = req.header[`user-agent`]; 

  res.json({ipaddress: ipAddress , language: 'language', software: 'software'}); 
})
  • this wont “extract” whoami, because "route does not have any “whoami” params in it!!
  • route is missing a “colon” infront of “whoami”, to be able to do so!!
  • what error do you get from this snippet?

happy coding :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.