Request-header-parser-microservice

What is your hint or solution suggestion?

We should extract the header from the request (in the form of an array). There’re several way to do that. One of them is to use Object.keys() and map()

let objectHeader = req.headers;

let result = Object.keys(objectHeader).map((key)=>[key,objectHeader[key]]);

From here we can get the information from result

res.json({
“ipaddress”: result[12][1],
“language”: result[4][1],
“software”: result[1][1]
})

But the check of freecodecamp require ipaddress to be “your ip” which seem to be weird. It will need additional work to get the real IP but in order to pass the check you can just type in any IP.

Another approach to get the header is using Object.entries(). Try this

Console.log( Object.entries(objectHeader));

This equivalent to result above. This method does not require extra memory
Challenge: Request Header Parser Microservice

Link to the challenge: