2.4 KiB
Demo — Inspecting HTTP Traffic
This demo runs a minimal Express server that echoes incoming requests (method, URL, headers, body) and exposes several small pages and endpoints you can use to explore HTTP behavior from both the browser and command line.
Quick setup
Install dependencies and start the dev server:
npm install
npm run dev
The server listens on http://localhost:3000.
What this demo provides
- A root page that shows the server's view of a GET request.
- A simple HTML form at
/formthat submits a POST and shows the server-echoed body. - Endpoints and pages demonstrating status codes, delayed responses, and cookie handling (
/status,/status-code,/delay,/set-cookie,/show-cookie). - Example static pages and client scripts in
src/and HTML partials insrc/partialsused to demonstrate injection and client behavior. - The server implementation in
server.tsthat logs each request and returns an echo response.
Walkthrough — what to try
-
Open http://localhost:3000 in the browser. In DevTools → Network inspect the GET request, then look at the server terminal to see the same information echoed.
-
Visit http://localhost:3000/form, fill it out, and submit. Observe the POST body in DevTools and the server log.
-
Compare browser requests with curl. Example commands:
# Basic GET
curl -v http://localhost:3000
# POST with urlencoded body
curl -v -X POST http://localhost:3000/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=user&password=1234"
# POST with JSON body
curl -v -X POST http://localhost:3000/api/json \
-H "Content-Type: application/json" \
-d '{"name":"alice"}'
# See only response headers
curl -I http://localhost:3000
-
Visit
/set-cookieto see the server send aSet-Cookieheader, then visit/show-cookie(or reload a page) to see the cookie sent back to the server. -
Try
/delayand watch how the browser and curl behave while the server delays its response. Use this to observe timeouts and loading indicators. -
Open
/statusand/status-codeendpoints to see different HTTP response codes and how clients report them.
Files of interest
server.ts— the Express server and request-echo logic.src/form.htmlandsrc/form.ts— the example form and client script.src/status.htmlandsrc/status.ts— status-code examples.src/partials/— HTML partials injected into pages by the demo plugin.