Python Rest API Example
This tutorial will explain how to implement simple Restful API in Python using Flask.
Q: What is Flask Python?
Ans:
A Python module that makes it simple to create web applications is called Flask. Its core is compact and simple to extend; it's a microframework that has lots of features, such as url routing and a template engine.
Refer steps to setup and install Python and Flask Virtual Environment
What is virtual environment in Python?
A virtual environment virtualenv
is used to create independent, separate virtual
environments with their own
dependencies for multiple project. It generates a new folder for the new virtual environment which
has its own libraries folder, pip, and
Python interpreter for the Python version used to activate the environment.
Follow the steps listed below to begin the project:
- Create a new virtual environment
- Select Python Interpreter
- Use new virtual environment for the python project
- Activate your new created virtualenv
- Install Flask if not available
- Create a new file called
app.py
in the python project and print the simple text using below code.from flask import Flask app = Flask(__name__) @app.route("/welcome") def welcome(): return "TechGeekNext - Python Example"
- Run python flask example
app.py
usingFlask run
command. - Test the Restful Api GET Request http://127.0.0.1:5000/welcome.