20/05/19 15 minutes read 1948 Naren Allam
In this article, I’ll explain you how to develop a web application using Flask-RESTplus with some APIs and dummy data. We will start our journey toward Flask-RESTplus Web APIs with Python 3.* that performs CRUD (short for Create, Read, Update, and Delete) operations on a sample data.
What is Flask-RESTPlus?
Flask-RESTPlus is an extension for Flask that adds support for quickly building REST APIs. Flask enables exposure of Python functions as APIs. Flask-RESTPlus is an extension to Flask which improves upon its capabilities. It allows us to not only define REST APIs but also brings in Swagger UI for all the APIs.
If you are familiar with Flask, Flask-RESTPlus should be easy to pick up. Flask-RESTPlus encourages best practices with minimal setup. It provides a coherent collection of decorators and tools to describe your API and expose its documentation properly (using Swagger).
SETUP AND INSTALLATION:-
➢ Ubuntu Desktop Linux 16.0.4/18.04
Steps for Installation
➢ Open terminal
➢ Update ‘sudo ‘ for latest system packages
➢ Create a directory for storing all the project files in that directory
Install pip3 package
➢ ‘pip3’ is for installing python packages. To install 'pip3' use the below command
Virtual Environment Creation
➢ It is a tool to create isolated python environments. It creates a folder which contains all the necessary packages that a python project would need.
➢ Create a folder with virtual environment
➢ Here “venv” is the virtual environment folder name , the folder name is of as your wish
Activate virtual environment
Deactivate virtual environment ➢ For de-activating the virtual environment, use command:
Now start install Flask and Flask-RESTPlus inside the virtual environment which we created. For that run the commands given below
Now we import Flask from flask and from flask_restplus, we import Api to define the app and Resource which is received as a parameter in the various classes defined in the project.
Now, define the application as a flask application using the method Flask() which sets the name using __name__. Next, we'll used Api to initialise the application as shown below.