Skip to content

tomBold/SimpleHttpServer

πŸš€ Simple HTTP Server

CI Tests Coverage Build Status TypeScript Node.js Express Jest ESLint License

A modern, well-tested TypeScript + Node.js REST API built with Express, featuring comprehensive testing, linting, and CI/CD pipeline.

✨ Features

  • πŸ”§ TypeScript - Full type safety and modern JavaScript features
  • πŸ§ͺ Comprehensive Testing - 9 passing tests with Jest and Supertest
  • πŸ” Code Quality - ESLint configuration for consistent code style
  • πŸš€ CI/CD Ready - GitHub Actions workflow for automated testing
  • πŸ“¦ Docker Support - Containerized deployment with Docker
  • πŸ›‘οΈ Security - Automated security audits and dependency checks
  • πŸ“Š Health Monitoring - Built-in health check endpoints
  • 🎯 RESTful API - Clean, intuitive API design

πŸš€ Quick Start

# Clone the repository
git clone https://github.com/tombo/SimpleHttpServer.git
cd SimpleHttpServer

# Install dependencies
npm install

# Run development server
npm run dev

# Server runs on http://localhost:3000

πŸ“‹ Available Scripts

Script Description
npm run dev Start development server with hot reload
npm run build Build TypeScript to JavaScript
npm start Start production server
npm test Run test suite
npm run test:watch Run tests in watch mode
npm run test:coverage Run tests with coverage report
npm run lint Run ESLint for code quality
npm run lint:fix Fix ESLint issues automatically

πŸ”— API Endpoints

Core Endpoints

  • GET / - Welcome message with server info
  • GET /health - Health check and server status

User Management

  • GET /api/users - Get all users
  • GET /api/users/:id - Get user by ID
  • POST /api/users - Create new user
  • PUT /api/users/:id - Update user
  • DELETE /api/users/:id - Delete user

Task Management

  • GET /api/tasks - Get all tasks (with optional filtering)
  • GET /api/tasks/:id - Get task by ID
  • GET /api/tasks/user/:userId - Get tasks by user
  • POST /api/tasks - Create new task
  • PUT /api/tasks/:id - Update task
  • DELETE /api/tasks/:id - Delete task

πŸ’‘ Example Usage

Create a User

curl -X POST http://localhost:3000/api/users \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "john@example.com",
    "age": 30
  }'

Create a Task

curl -X POST http://localhost:3000/api/tasks \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Learn TypeScript",
    "description": "Complete TypeScript tutorial",
    "userId": "1"
  }'

Get All Users

curl http://localhost:3000/api/users

Health Check

curl http://localhost:3000/health

πŸ§ͺ Testing

The project includes comprehensive test coverage:

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

Test Results:

  • βœ… 9 tests passing
  • βœ… 2 test suites
  • βœ… User API tests
  • βœ… Task API tests

🐳 Docker Support

# Build Docker image
docker build -t simple-http-server .

# Run with Docker Compose
docker-compose up

# Run in production mode
docker-compose -f docker-compose.yml up -d

πŸ”§ Development

Prerequisites

  • Node.js 18.x or 20.x
  • npm or yarn

Project Structure

src/
β”œβ”€β”€ __tests__/          # Test files
β”œβ”€β”€ controllers/        # Route controllers
β”œβ”€β”€ middleware/         # Express middleware
β”œβ”€β”€ routes/            # API routes
β”œβ”€β”€ validation/        # Validation schemas
β”œβ”€β”€ database.ts        # In-memory database
β”œβ”€β”€ server.ts          # Express server setup
└── types.ts           # TypeScript type definitions

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

If you have any questions or need help, please:

  • Open an issue on GitHub
  • Check the existing documentation
  • Review the test files for usage examples

⭐ Star this repository if you found it helpful!

About

SimpleHttpServer

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published