Build REST API with Flask

This article will show you how to use Flask framework to build rest api server on MacOS.

Setup Python Environment

Install Flask

Create your project folder, eg. market-watcher, then create a folder named .venv

Run below command to create a virtual environment for python.

python3 -m venv .venv

Then activate the virtual environment by running below command:

. .venv/bin/activate

You should have a (.venv) in front of your current path

Run below command to install Flask

pip install Flask

Now you should have Python Flask environment ready

Build First Rest API

Create a python file called hello_world.py under market-watcher folder

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"

Run below command start web server

flask --app hello_world run

Example Output

Your web app is available at : http://127.0.0.1:5000

Reference

Leave a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Scroll to Top