Skip to content

Instantly share code, notes, and snippets.

@eredo

eredo/server.py Secret

Last active February 10, 2022 17:11
Show Gist options
  • Save eredo/1547873c189ed5ced7353d6217cfeb42 to your computer and use it in GitHub Desktop.
Save eredo/1547873c189ed5ced7353d6217cfeb42 to your computer and use it in GitHub Desktop.
Simple python HTTP server
# Python 3
from http.server import BaseHTTPRequestHandler, HTTPServer
class SimpleServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
self.wfile.write(bytes('{"hello": "world"}', 'utf-8'))
hostname = "0.0.0.0"
port = 8080
if __name__ == "__main__":
server = HTTPServer((hostname, port), SimpleServer)
print("HTTP server started at: http://%s:%s" % (hostname, port))
try:
server.serve_forever()
except KeyboardInterrupt:
pass
server.server_close()
print("HTTP server stopped")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment