/Whoami-Microservice

🔗 Request header Parser that extracts and returns a JSON object containing the IP address, language, and software keys from the request header. ❓

Primary LanguageJavaScript

Whoami Microservice

Banner

Javascript Node.js Express.js Jest JSON

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.

Features

  • 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.

Requirements

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.

Core

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
  });
});

Installation

To install and run the project:

  1. Install dependencies using the following command:

    npm install
    
  2. Start the server using the following command:

    node index.js
    

License

MIT License

Thank you for checking it out!