A microservice which returns the client's IP address, preferred language, and software.
git clone https://github.com/AngeliqueDF/request-header-parser-microservice-challenge.git MY-FOLDER-NAME
cd MY-FOLDER-NAME
- Add
.env
file with aPORT
value npm install
npm start
- Visit
http://localhost:{PORT}
- Parses the request's headers to return information about it.
- Handles requesting an unknown URL.
node
express
helmet
- Bootstrap
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.
Once the server is listening, there are different ways to test this microservice:
- Open the terminal
- Enter
curl http://localhost:5000/api/whoami
- Create a new file from the terminal
touch request.rest && code request.rest
. - In
request.rest
, enterGET http://localhost:5000/api/whoami
. - Click on the
Send request
link that appears above the request you entered in step 2. - Once a response is received from the server, its body and headers will be displayed in a new editor tab.
Visit the http://localhost:5000/api/whoami endpoint in your browser (use the JSONVue extension to format the response, or use Firefox).
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.
Returns information on the request.
GET localhost:{PORT}/api/whoami/
None. All values are taken from the request's headers.
{
"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"
}
nodemon
to restart the server after each save..- JSONVue.
- REST Client VS Code extension.
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.
- Improve security.