Creating a Python Web Server from First Principles

We’ve all heard of Web Servers. Many frameworks and libraries we use abstract us from the inner-workings, allowing us to build complex applications at a higher-level. This is a good thing, but sometimes it helps to start from the building blocks.

Here, we’re building a very simple web server using just sockets. We’ll set up the server to return mock http data.

And that’s all that’s required. If you run this and visit http://localhost:9000 in your web browser, you’ll get served with ‘Hello, World!’.

The sample code here is very rudimentary, and its only purpose is demonstrating how this works. However HTTP/1 in itself isn’t a complex protocol.

In upcoming articles we’ll discuss HTTP in more detail, and look into ways of improving the above code. We’ll also be looking into the added complexities of HTTP/2 and how this improves on the previously used protocol.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store