A professional-grade REST API implementation showcasing enterprise security features and best practices. Built over 4 weeks with focus on security, scalability, and maintainability.
- Header-based authentication
- Secure key validation
- Environment-based configuration
curl -H "X-API-Key: your-api-key" http://localhost:3000/api/health- Request throttling
- Redis support for production
- Configurable limits
{
"RateLimit-Limit": "100",
"RateLimit-Remaining": "99",
"RateLimit-Reset": "60"
}- Input sanitization
- HTML/Script stripping
- Safe output encoding
// Input: <script>alert("xss")</script>John<p>Test</p>
// Output: "John"- Content Security Policy (CSP)
- HSTS
- XSS Protection
- Frame Options
- And more...
- Clone the repository
git clone https://github.com/yourusername/basic-restful-api.git
cd basic-restful-api- Install dependencies
npm install- Set up environment variables
cp .env.example .env
# Edit .env with your settings- Start the server
npm run dev- View API documentation
http://localhost:3000/api-docs
Run the test suite:
npm testRun security checks:
npm run security-demo- ✅ API Key Authentication
- ✅ Rate Limiting
- ✅ Input Sanitization
- ✅ XSS Prevention
- ✅ Security Headers
- ✅ Error Handling
- ✅ Input Validation
- ✅ Secure Defaults
- Node.js 18+
- npm or yarn
- Redis (optional, for production)
.
├── src/
│ ├── config/ # Configuration files
│ ├── middleware/ # Custom middleware
│ ├── routes/ # API routes
│ └── types/ # TypeScript types
├── docs/ # Documentation
├── scripts/ # Utility scripts
└── tests/ # Test suites
npm run dev: Start development servernpm test: Run test suitenpm run build: Build for productionnpm run security-demo: Run security demonstrationnpm run lint: Run linternpm run format: Format code
- ✅ Project setup
- ✅ Basic API structure
- ✅ TypeScript configuration
- ✅ API key authentication
- ✅ Rate limiting
- ✅ Security headers
- ✅ Request sanitization
- ✅ XSS prevention
- ✅ Error handling
- ✅ API documentation
- ✅ Security testing
- ✅ Performance optimization
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is ISC licensed. See the LICENSE file for details.
- GitHub: @lovingthemoo
- Email: lovingthemoo@gmail.com
Made with ❤️ by lovingthemoo