Skip to content

Instantly share code, notes, and snippets.

@drgarcia1986
Created September 25, 2018 17:53
Show Gist options
  • Save drgarcia1986/5deba4c341747825a8a7bdfe1e5ae155 to your computer and use it in GitHub Desktop.
Save drgarcia1986/5deba4c341747825a8a7bdfe1e5ae155 to your computer and use it in GitHub Desktop.
simple python built-in web hello world
from http.server import BaseHTTPRequestHandler, HTTPServer
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200, 'OK')
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(b'{"message": "hello world"}')
if __name__ == '__main__':
server = HTTPServer(('', 8080), Handler)
try:
server.serve_forever()
except KeyboardInterrupt:
server.socket.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment