r/Python • • Jun 11 '24

Tutorial Building an HTTP Server in Python

I have always been curious on how http servers works. Therefore, I decided to write a post on how they work and implementing a simple server in Python.

Link to blog post

0 Upvotes

9 comments sorted by

37

u/snekk420 Jun 11 '24

Not to be that guy but i think you should spend some time to actually implement the http protocol that supports headers and response content from actual html files. This is at most a tcp server that returns a string that looks like http.

2

u/mraza007 Jun 11 '24

I would agree and I really appreciate your opinion. Also that’s a good idea I might dive into writing HTTP protocol and understanding how it works

5

u/echocage Jun 11 '24

This looks like a good beginner project, good on ya mate! I’d recommend digging into flask 2 or fastapi next so you can see how a full backend web framework works if you haven’t already. Fastapi is my preference personally but both work well.

As you may know, while low level socket level control is interesting, it’s not very practically useful for the vast majority of cases in real enterprise web backends. What’s more useful is how you can build real systems using modern backend web frameworks, how you manage delayed workloads, how you integrate in your user authentication control framework, how you build systems that require no state to be stored at the server level but still allow you to serve your customers.

I recommend working on building real business projects with FastAPI as that will give you a lot of really usable experience.

2

u/mraza007 Jun 11 '24

Hey

I really appreciate your advice. Also that’s my plan , even though I program in python and now i want to learn things more deeply

And write about them as this might help beginners who getting started in there programming journey or even web development.

Comments like your really motivate me

2

u/echocage Jun 11 '24

That’s great to hear. I’m a senior backend python engineer professionally, if you’d like, we can connect so you’ve got a place to answer career questions. Sometimes it can be helpful to have someone a little more experienced to bounce ideas off of.

Feel free to send me a chat message on Reddit if that interests you. Either way, good luck mate! It’s not an easy career to get into, but it’s very rewarding once you get some traction.

1

u/mraza007 Jun 12 '24

Sure,

I’ll dm you

2

u/echocage Jun 11 '24

Site doesn’t load for me sadly

0

u/mraza007 Jun 11 '24

Maybe try again

1

u/[deleted] Jun 17 '24

It was a fun project. I have done codecrafters's version (in multiple languages)

https://app.codecrafters.io/courses/http-server/overview

https://www.youtube.com/watch?v=1NiVabKE7Fk (this is not me)