Skip to content

AngeliqueDF/request-header-parser-microservice

Repository files navigation

Request Header Parser Microservice

request-header-parser-microservice

Overview

A microservice which returns the client's IP address, preferred language, and software.

Links

GitHub repo


How to run the project

  1. git clone https://github.com/AngeliqueDF/request-header-parser-microservice-challenge.git MY-FOLDER-NAME
  2. cd MY-FOLDER-NAME
  3. Add .env file with a PORT value
  4. npm install
  5. npm start
  6. Visit http://localhost:{PORT}

Features

  • Parses the request's headers to return information about it.
  • Handles requesting an unknown URL.

Technologies

  • node
  • express
  • helmet
  • Bootstrap

Description

This project is an Express.js app which parses specific headers from a request and returns them in a JSON object. It could be used in an analytics software, a data analytics API, or a logging system, for example.

It's my solution to freeCodeCamp's Request Header Parser Microservice challenge.

How to test the app (manually)

Once the server is listening, there are different ways to test this microservice:

Using the curl utility

  1. Open the terminal
  2. Enter curl http://localhost:5000/api/whoami

Using the REST Client VS Code extension

  1. Create a new file from the terminal touch request.rest && code request.rest.
  2. In request.rest, enter GET http://localhost:5000/api/whoami.
  3. Click on the Send request link that appears above the request you entered in step 2.
  4. Once a response is received from the server, its body and headers will be displayed in a new editor tab.

In the browser

Visit the http://localhost:5000/api/whoami endpoint in your browser (use the JSONVue extension to format the response, or use Firefox).

How I built this project

I completed this app using Express' documentation. I replaced the original frontend by serving the HTML and JavaScript files required.

The CSS is a minified Bootstrap stylesheet served from a CDN.

Then I added security measures with helmet although this aspect still needs to be improved.

API

Get the parsed headers

Returns information on the request.

GET localhost:{PORT}/api/whoami/

Parameters

None. All values are taken from the request's headers.

Example response

{
	"ipaddress": "159.20.14.100",
	"language": "en-US,en;q=0.5",
	"software": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0"
}

Recommended technologies and tools


Status

The app is functional but needs security improvements.

Data coming from clients is processed without any check. Trusting input from the client can leave the app vulnerable to malicious requests.

Planned changes

  • Improve security.

Sources

Useful references

  1. req.ip from the Express documentation.
  2. req.get(field) from the Express documentation.

Author

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published