Quickstart!
Flask is one of the most famous Python-based Web frameworks.
Here is the code provided in the Flask documentation quickstart:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
Let's also see how we can do the same thing in MinHTTP.
To do this though, you need a few more steps:
cd
into the MinHTTP directory.
cd minhttp
- Create a new file called
app.py
and add the following code:
from minhttpserver import MinHTTPServer
from response import text_response
app = MinHTTPServer(host="localhost", port=8080)
@app.get("/")
def hello_world(request):
return text_response("Hello, World!")
if __name__ == "__main__":
app.run()
- Run the server:
python app.py
Voila! You have a simple web server running on http://localhost:8080
that returns Hello, World!
when you visit localhost:8080/
. You can check it with your browser, or with HTTP tools like HTTPie!
Note
In this small demo the SSL/TLS is not enabled. So, be sure you are using HTTP instead of HTTPS when you are testing. We will talk about enabling SSL/TLS in later sections.