A lightweight Node.js module that provides convenient getters for HTTP request properties. This module extends the functionality of the standard HTTP request object with easy-to-use getters for common request properties like cookies, body, query parameters, and more.
Just make sure the node-modules
folder includes the http-getters
module folder with its index.js
inside it. You can’t install it from the NPM normally as it isn’t published there.
cookie
: Returns parsed cookies as an objectrawBody
: Returns the raw request body as a stringbody
: Returns parsed JSON body (if valid JSON) or raw bodypath
: Returns URL path without query parametersquerystring
: Returns the raw query stringquery
: Returns parsed query parameters as an objectYou can test the module using curl commands, Postman, browser or any other way. Here are some examples:
curl 'http://localhost:3000/test'
curl 'http://localhost:3000/test?name=john&age=25'
curl -H 'Cookie: session=abc123; user=john' 'http://localhost:3000/test'
curl -X POST \
'http://localhost:3000/api/data?id=123' \
-H 'Content-Type: application/json' \
-H 'Cookie: session=xyz789' \
-d '{"message": "Hello World"}'
This command tests all getters at once:
curl -X POST \
'http://localhost:3000/test/path?key1=value1&key2=value2' \
-H 'Cookie: session=abc123; user=john' \
-H 'Content-Type: application/json' \
-d '{"message": "Hello World"}'
The server will log in its console:
http
(Node.js built-in)c4console
(for logging)Feel free to submit issues and enhancement requests.
MIT