Created
September 25, 2018 17:53
-
-
Save drgarcia1986/5deba4c341747825a8a7bdfe1e5ae155 to your computer and use it in GitHub Desktop.
simple python built-in web hello world
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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