Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions middleware-Ex1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
55 changes: 55 additions & 0 deletions middleware-Ex1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Middleware Exercise 1 – Custom Express Middlewares

## Description

This project is a small Express application demonstrating how to create and use **custom middleware**.

The application includes:

* A middleware that reads the `X-Username` request header and attaches it to the request
* A middleware that manually parses the POST request body as a JSON array of strings
* A POST endpoint that uses the data provided by the middlewares to build a response

---

## Setup & Run

```bash
npm install
node server.js
```

Server runs on:

```
http://localhost:3000
```

---

## POST Request

* Endpoint: `POST /`
* Body must be a **JSON array of strings**
* Header `X-Username` is optional

---

## Example Request

```bash
curl -X POST \
-H "X-Username: Ahmed" \
--data '["Bees"]' \
http://localhost:3000
```

---

## Example Response

```
You are authenticated as Ahmed.
You have requested information about 1 subject: Bees.
``

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Many trainees haven't bothered with this file, but adding a readme like this is an excellent habit to get into.

---
Loading
Loading