Skip to content

Repository files navigation

Python Basic Server

A simple Flask-based HTTP server with basic REST endpoints.

Setup

  1. Activate the virtual environment:
source .venv/bin/activate
  1. Install dependencies (if not already installed):
pip install -r requirements.txt

Running the Server

python app.py

The server will start on http://localhost:3000

Running Tests

Run all tests:

pytest

Run tests with verbose output:

pytest -v

Run a specific test file:

pytest tests/test_app.py

Run a specific test class or test method:

pytest tests/test_app.py::TestRootEndpoint
pytest tests/test_app.py::TestRootEndpoint::test_root_endpoint_returns_200

The test suite includes 16 tests covering all endpoints, status codes, JSON responses, and edge cases.

Linting and Formatting

Linting with flake8

Check code for style and quality issues:

flake8 app.py tests/

Check specific files or directories:

flake8 app.py
flake8 tests/

Formatting with black

Check if code needs formatting (without making changes):

black --check app.py tests/

Format code automatically:

black app.py tests/

Format all Python files in the project:

black .

Note: Configuration files (.flake8 and pyproject.toml) are already set up with appropriate settings.

Available Endpoints

  • GET / - Welcome message
  • GET /health - Health check endpoint
  • GET /api/hello - Simple hello message
  • GET /api/hello/<name> - Personalized hello message

Example Requests

# Root endpoint
curl http://localhost:3000/

# Health check
curl http://localhost:3000/health

# Hello endpoint
curl http://localhost:3000/api/hello

# Personalized hello
curl http://localhost:3000/api/hello/John

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages