- Table of Contents
- Features
- Tech Stack
- Getting Started
- Environment Variables
- Project Structure
- Demo
- API Reference
- Contributing
- License
- User registration and login with session token authentication
- Password hashing with HMAC SHA-256 and random salt
- Session token stored in cookies for authentication
- CRUD operations for products (create, read, update, delete)
- CRUD operations for users (read, update, delete)
- Ownership middleware to protect product modifications
- Authentication middleware for protected routes
- Angular 17 standalone frontend with Angular Material UI
- Auth guard and HTTP interceptor for frontend authentication
- Reactive forms for product management
- MongoDB with Mongoose ODM
- TypeScript on both backend and frontend
- Hot reload with Nodemon during development
- Node.js 18+
- npm
- A MongoDB instance (local or MongoDB Atlas)
git clone https://github.com/wrujel/rest-api-et.git
cd rest-api-et
npm install
cd frontend/angular
npm install
cd ../..npm run devOpen http://localhost:8080 with your browser to see the result.
npm run buildTo run this project, you will need to add the following environment variables to your .env file.
| Variable | Description | Required |
|---|---|---|
MONGO_URL |
MongoDB connection string | Yes |
SECRET |
Secret key used for HMAC password hashing | Yes |
PORT |
Server port (defaults to 8080) | No |
FRONTEND_BUILD_PATH |
Path to the Angular frontend build output | No |
ENVIRONMENT |
Set to development to enable session token in login response and header-based auth |
No |
/
├── public/
│ └── screenshot.png
├── src/
│ ├── controllers/
│ │ ├── authentication.ts
│ │ ├── products.ts
│ │ └── users.ts
│ ├── db/
│ │ ├── product.ts
│ │ └── users.ts
│ ├── helpers/
│ │ └── index.ts
│ ├── middlewares/
│ │ └── index.ts
│ ├── router/
│ │ ├── authentication.ts
│ │ ├── index.ts
│ │ ├── products.ts
│ │ └── users.ts
│ └── index.ts
├── frontend/
│ └── angular/
│ └── src/
│ └── app/
│ ├── components/
│ │ ├── api-card/
│ │ ├── home/
│ │ ├── login/
│ │ ├── navbar/
│ │ └── register/
│ ├── models/
│ ├── services/
│ └── app.routes.ts
├── package.json
├── tsconfig.json
└── nodemon.json
You can check out the demo:
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/auth/register |
Register a new user | No |
POST |
/api/auth/login |
Login and get session token | No |
GET |
/api/users |
List all users | Yes |
DELETE |
/api/users/:id |
Delete a user by ID | Yes (Owner) |
PATCH |
/api/users/:id |
Update a user's username | Yes (Owner) |
GET |
/api/products |
List all products | Yes |
POST |
/api/products |
Create a new product | Yes |
PUT |
/api/products |
Update a product (id via query param) | Yes (Owner) |
DELETE |
/api/products |
Delete a product (id via query param) | Yes (Owner) |
Contributions are welcome! If you have suggestions or find bugs, please open an issue or submit a pull request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.