[PYTHON] Create a "Hello World" (HTTP) server with Tornado

Introduction

Tornado is a web framework / network library in Python.

Installation

$ pip install tornado --user
Collecting tornado
Collecting singledispatch (from tornado)
  Using cached singledispatch-3.4.0.3-py2.py3-none-any.whl
Collecting certifi (from tornado)
  Using cached certifi-2016.9.26-py2.py3-none-any.whl
Collecting backports-abc>=0.4 (from tornado)
  Using cached backports_abc-0.5-py2.py3-none-any.whl
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado)
Installing collected packages: singledispatch, certifi, backports-abc, tornado
Successfully installed backports-abc-0.5 certifi-2016.9.26 singledispatch-3.4.0.3 tornado-4.4.2

"Hello World" (HTTP) server

A web server that returns "Hello World" with GET access to /.

server.py


import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello World\n");

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler)
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

Start the server

$ python server.py

Access from client

$ wget -q -O - http://localhost:8888/
Hello World

Impressions

--Ok

Recommended Posts

Create a "Hello World" (HTTP) server with Tornado
Create a one-file hello world application with django
Start a temporary http server locally with Pytest
[AWS] Create a Python Lambda environment with CodeStar and do Hello World
hello world with ctypes
Hello, World with Docker
Hello world with flask
A web app that just does Hello World with Go's net / http package
Create a home music server with Centos8 + Universal Media Server
Create a web server in Go language (net / http) (1)
Create a fake Minecraft server in Python with Quarry
Draw hello world with mod_wsgi
Hello World with Flask + Hamlish
Create a (simple) REST server
Create a homepage with django
Create a heatmap with pyqtgraph
Easy HTTP server with Python
Create a simple textlint server
Python starting with Hello world!
[Python] Create a screen for HTTP status code 403/404/500 with Django
Hello, world! With virtual CAN communication
Create a virtual environment with Python!
Create a Unix Domain Socket server
Hello World! By QPython with Braincrash
Create a poisson stepper with numpy.random
Create a file uploader with Django
Hello World and face detection with opencv-python 4.2
Create a Python function decorator with Class
Build a blockchain with Python ① Create a class
Create a dummy image with Python + PIL.
Set up a Samba server with Docker
Hello World with Raspberry Pi + Minecraft Pi Edition
Create your own DNS server with Twisted
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Create a GUI app with Python's Tkinter
Create a large text file with shellscript
Create a star system with Blender 2.80 script
Create a virtual environment with Python_Mac version
Build a CentOS Linux 8 environment with Docker and start Apache HTTP Server
Create a simple web app with flask
Create a Connecting Nearest Neighbor with NetworkX
A typed world that begins with Python
Create a web service with Docker + Flask
Create a private repository with AWS CodeArtifact
Create a car meter with raspberry pi
Create a devilish picture with Blender scripts
Create a matrix with PythonGUI (text box)
Hello World! By QPython with Brainfu * k
Create a graph with borders removed with matplotlib
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
Hello World and face detection with OpenCV 4.3 + Python
Create a frame with transparent background with tkinter [Python]
Build a local server with a single command [Mac]
Set up a simple HTTPS server with asyncio
Hello World with gRPC / go in Docker environment
Set up a local server with Go-File upload-
Hello world with full features of Go language
Until and after becoming [Kaggle Master]
Hello world
Create a one-file hello world application with django
Create a "Hello World" (HTTP) server with Tornado
To myself as a Django beginner (3)-Hello world! ---
Create a LINE BOT with Minette for Python
Create a game UI from scratch with pygame2!