A simple Node.js and Express application designed for testing and experimenting with HTTP status codes. This tool allows you to trigger specific status codes and observe how your client-side applications or infrastructure (like load balancers or proxies) handle them.
- Dynamic Status Codes: Return any HTTP status code by simply changing the URL.
- Content Negotiation: Supports both JSON (default) and XML responses based on the
Acceptrequest header. - Lightweight: Minimal dependencies, built on Express 5.x.
- Test-Ready: Includes a comprehensive test suite using Jest and Supertest.
- Node.js (version 18.0.0 or higher)
- npm (comes with Node.js)
-
Clone the repository:
git clone https://github.com/cybo42/httpstatus.git cd httpstatus -
Install dependencies:
npm install
Start the server locally:
npm startBy default, the application will listen on port 8888. You can customize this by setting the PORT environment variable:
PORT=3000 npm startReturns the HTTP status code specified in the URL path.
JSON Response (Default)
curl -i http://localhost:8888/code/404XML Response
curl -i -H "Accept: application/xml" http://localhost:8888/code/200- JSON:
{"code": 200} - XML:
<?xml version="1.0" encoding="UTF-8"?> <response> <code>200</code> </response>
The project uses Jest for testing and Supertest for HTTP assertions.
To run the tests:
npm testThis will run all unit and integration tests and generate a coverage report in the coverage/ directory.
This project is open-source. (Check for a LICENSE file for specific terms).