File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ # Middleware Exercise 1 – Custom Express Middlewares
2+
3+ ## Description
4+
5+ This project is a small Express application demonstrating how to create and use ** custom middleware** .
6+
7+ The application includes:
8+
9+ * A middleware that reads the ` X-Username ` request header and attaches it to the request
10+ * A middleware that manually parses the POST request body as a JSON array of strings
11+ * A POST endpoint that uses the data provided by the middlewares to build a response
12+
13+ ---
14+
15+ ## Setup & Run
16+
17+ ``` bash
18+ npm install
19+ node server.js
20+ ```
21+
22+ Server runs on:
23+
24+ ```
25+ http://localhost:3000
26+ ```
27+
28+ ---
29+
30+ ## POST Request
31+
32+ * Endpoint: ` POST / `
33+ * Body must be a ** JSON array of strings**
34+ * Header ` X-Username ` is optional
35+
36+ ---
37+
38+ ## Example Request
39+
40+ ``` bash
41+ curl -X POST \
42+ -H " X-Username: Ahmed" \
43+ --data ' ["Bees"]' \
44+ http://localhost:3000
45+ ```
46+
47+ ---
48+
49+ ## Example Response
50+
51+ ```
52+ You are authenticated as Ahmed.
53+ You have requested information about 1 subject: Bees.
54+ ``
55+ ---
You can’t perform that action at this time.
0 commit comments