Whoami Microservice is a request header Parser that extracts and returns a JSON object containing the IP address, language, and software keys from the request header.
This project is my solution for the APIs and Microservices Projects - Request Header Parser Microservice, which is part of the APIs and Microservices Certification by freeCodeCamp.
- Parses request headers to extract IP address, language, and software information.
- Returns a JSON object with IP address, language, and software information.
- Provides a simple solution for implementing a request header parser microservice.
To meet the requirements of the project, the microservice should:
- Return a JSON object with the IP address in the ipaddress key when the endpoint /api/whoami is accessed.
- Return a JSON object with the preferred language in the language key when the endpoint /api/whoami is accessed.
- Return a JSON object with the software in the software key when the endpoint /api/whoami is accessed.
app.get("/api/whoami", (req, res) => {
res.json({
ipaddress: req.ip, // The IP address of the client making the request
language: req.headers["accept-language"], // The language accepted by the client
software: req.headers["user-agent"], // The client's user agent information
});
});
To install and run the project:
-
Install dependencies using the following command:
npm install
-
Start the server using the following command:
node index.js
Thank you for checking it out!