A simple HTTP server built using pure Python with support for custom route handlers and path/query parameters. Inspired by web frameworks but designed to be lightweight and educational.
- Async server using
asyncio
- Routing with path and query parameter support
- Pluggable HTTP method handlers via subclassing
- Clean separation of request, response, and routing logic
- Clone this repo or copy the structure.
- Create an
app/
directory and define your routes and handlers there.
from http.handler import HTTPHandler
from http.response import HTTPResponse
from http.router import router
class EchoHandler(HTTPHandler):
def get(self, request):
word = request.path_params.get("word", "nothing")
return HTTPResponse(
status_code=200,
body=f"Echo: {word}"
)
# Register route
router.add_route("/echo/:word", EchoHandler())
- Run the server using:
python -m http.server