Skip to content

Instantly share code, notes, and snippets.

@davidbgk
Created April 11, 2017 15:39
Show Gist options
  • Save davidbgk/b10113c3779b8388e96e6d0c44e03a74 to your computer and use it in GitHub Desktop.
Save davidbgk/b10113c3779b8388e96e6d0c44e03a74 to your computer and use it in GitHub Desktop.
An attempt to create the simplest HTTP Hello world in Python3
import http.server
import socketserver
from http import HTTPStatus
class Handler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(HTTPStatus.OK)
self.end_headers()
self.wfile.write(b'Hello world')
httpd = socketserver.TCPServer(('', 8000), Handler)
httpd.serve_forever()
# python3 server.py
# 127.0.0.1 - - [11/Apr/2017 11:36:49] "GET / HTTP/1.1" 200 -
# http :8000
'''
HTTP/1.0 200 OK
Date: Tue, 11 Apr 2017 15:36:49 GMT
Server: SimpleHTTP/0.6 Python/3.5.2
Hello world
'''
@davidbgk
Copy link
Author

davidbgk commented Aug 5, 2020

even you can use enums

@vaibhavkumar049 sure, at that point, you may even want to use a dedicated lib for that, like autoroutes (shameless plug).

@vaibhavkumar049
Copy link

even you can use enums

@vaibhavkumar049 sure, at that point, you may even want to use a dedicated lib for that, like autoroutes (shameless plug).

yeah, I had very small task so I was fine with self.path , but sure I will keep that in mind

@davidbgk
Copy link
Author

davidbgk commented Jul 9, 2022

This gist being relatively popular, if you want to go further you can check:

https://github.com/kadircancetin/MostMinimalWebFramework/blob/main/MostMinimalWebFramework.py

@deepakk15
Copy link

cmd is "python3 server.py " for who are asking how to use this file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment