A comprehensive REST API for a blogging platform built with NestJS, PostgreSQL, and TypeORM. Features include JWT authentication, post management, comprehensive unit testing, and an interactive HTML browser tester for easy API testing.
Open api-test.html in your browser for an interactive web interface to test all API endpoints:
- 🔐 User registration and authentication
- 📝 Complete CRUD operations for blog posts
- 🎫 Automatic JWT token management
- 🎨 Beautiful, responsive interface
- ⚡ Real-time API response display
- JWT-based authentication system with secure password hashing
- Environment-based configuration management
- Input validation and comprehensive error handling
- Role-based access control for post management
- PostgreSQL database with TypeORM integration
- Entity relationships and migrations
- Optimized queries and database performance
- Complete CRUD operations for blog posts
- User management and profile handling
- RESTful API design with proper HTTP status codes
- Comprehensive error handling and validation
- 100% unit test coverage with Jest
- Integration testing for all endpoints
- Clean, modular architecture following NestJS best practices
- TypeScript for type safety and better developer experience
- Interactive HTML interface for API testing
- No additional tools required - just open in browser
- Real-time response visualization
- Pre-filled test data for quick testing
- Framework: NestJS
- Database: PostgreSQL
- ORM: TypeORM
- Authentication: JWT (JSON Web Tokens)
- Validation: class-validator & class-transformer
- Testing: Jest
- Language: TypeScript
- Node.js 16+
- PostgreSQL 12+
npm installCreate .env file:
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USERNAME=postgres
DATABASE_PASSWORD=your_password
DATABASE_NAME=blog_db
JWT_SECRET=your_secret_key
JWT_EXPIRES_IN=1d
PORT=3000# Development mode (with hot reload)
npm run start:dev
# Production mode
npm run build
npm start
# Watch mode for development
npm run start:debug-
Start the API server:
npm run start:dev
-
Open
api-test.htmlin your browser -
Test all endpoints interactively:
- Sign up new users
- Authenticate and get JWT tokens
- Create, read, update, and delete blog posts
- View real-time API responses
POST /auth/signup- Register new userPOST /auth/signin- Login user
POST /posts- Create postGET /posts- Get all postsGET /posts/my-posts- Get user's postsGET /posts/:id- Get post by IDPATCH /posts/:id- Update postDELETE /posts/:id- Delete post
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Generate test coverage report
npm run test:cov
# Run end-to-end tests
npm run test:e2e- Use the included
api-test.htmlfor browser-based testing - Use tools like Postman or curl for API testing
- All endpoints include proper error handling and validation
src/
├── 🔐 auth/
│ ├── auth.controller.ts # Authentication endpoints
│ ├── auth.service.ts # Authentication logic
│ ├── jwt.strategy.ts # JWT strategy
│ ├── jwt-auth.guard.ts # JWT guard
│ └── dto/auth.dto.ts # Data transfer objects
├── 👤 user/
│ ├── user.entity.ts # User database entity
│ ├── user.service.ts # User business logic
│ └── user.module.ts # User module
├── 📝 post/
│ ├── post.controller.ts # Post CRUD endpoints
│ ├── post.service.ts # Post business logic
│ ├── post.entity.ts # Post database entity
│ └── dto/create-post.dto.ts # Post DTOs
├── 🛡️ common/
│ └── http-exception.filter.ts # Global exception filter
└── 🏠 app.module.ts # Main application module
📄 Root Files:
├── api-test.html # 🌟 Browser API tester
├── README.md # Documentation
├── package.json # Dependencies
└── .env.example # Environment template
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Repository: https://github.com/35sonu/Blog-API-Tester
- Issues: https://github.com/35sonu/Blog-API-Tester/issues
- Documentation: README.md
35sonu
- GitHub: @35sonu
- Repository: Blog-API-Tester
⭐ Star this repository if you find it helpful! ⭐