Hint for reeCodeCamp Challenge: Request Header Parser Microservice

Challenge: Request Header Parser Microservice

Hint and Solution Suggestion:

Hint 1:

You can find some the values needed here
http://expressjs.com/en/5x/api.html#req

Some of the property indentifiers/keys are instant giveaways.

Hint 2:

The req.accept-languages() function on that linked page above, will return the language (s) but as an array . If you want a plan string, you could try to use an array method or you could…

Hint 3:
Go to your repl.it do this:

Type console.log(req) or console.log(req.body) within your handler function for accessing the information and then run the FCC test and it will show the req or req.body. in the terminal.

Then click the search icon in the terminal and type in “language” and begin searching. Soon you’ll find “accept-language” property which has a string value for the language, and if you look closely, you see that it’s in the “headers” object which also contains the “user-agent” property which is the “software” value.

Contains part of solution:

app.get("/api/whoami", function handlerFunction(req, res) { 
    // console.log(req.body) // don't forget to run the FCC test 

    res.json({
        ipaddress: req.ip,
        language: "You can find me in headers object, use bracket notation to access me.",
        software: "I'm in headers too"
    });
}

I’m not for sure if I did this right or if it’s a good way to do it, but I did eventually pass all the FCC Test for this challenge.

I hope you have a very blessed day. :smile_cat:

Link to the challenge: