Create and deploy a flask API in Heroku (Part 2)

Photo by Cookie the Pom on Unsplash

Hi All, welcome back to the second part of creating and deploying a flask API in Heroku.

In the previous post, we have developed a flask API and tried it in localhost. In this post, we will commit the code to GitHub and deploy it in Heroku.

Before we begin let's complete few steps that are pending.

Install gunicorn

Gunicorn is a Python WSGI HTTP server that will serve your Flask application.

pip install gunicorn

Now you need to create requirements.txt in the project root folder, else the Heroku application will fail to deploy. Run the below command to fetch all the dependencies used in your project.

pip freeze > requirements.txt

Adding a Procfile

Create a Procfile in the project root folder and add the following line:

web: gunicorn app:app

The first app represents the name of the python file that runs your application. The second app represents your app name.

Our project should have the folder structure as shown below. you can find all the code and folder structures here.

Let's deploy our code in Heroku. To begin that let's create a repo in your GitHub and commit all our codes into the repo.

Creating a Github Repo

Let’s create a GitHub repo and commit our code to it.

Creating a Heroku application

Log in to your Heroku account and create a new app with a unique name.

To add the remote GitHub repository, select Github as a deployment method and link the GitHub repo we have created earlier.

After that select Deploy Branch which reads the Procfile and install all the dependencies in the requirements file and deploy it.

Once deployed you can access your app using https://<app name>

Now that we have created and deployed a flask API, let's test it in postman.

Accessing Flask API in postman

Let's add a product by calling a POST method.

Now we will try to retrieve the products by calling a GET method.

Similarly, you can try calling other methods too.


From this series, we have learned how to create a new flask restful-API app and deploy it in Heroku.

For part 1 refer here

Stay healthy, stay safe. will meet you all in a new blog




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

BOOTSTRAP: A FRONT END LIBRARY Good Afternoon, I trust you have been expecting me.

Safe data upgrade without downtime?

EDA Tools: Simulink & Electric

Control Tutorials for MATLAB and Simulink — Suspension: Simulink Control

Working with XML tree data in Python

Why we started riding Release Trains for our Mobile Applications

Kubernetes metallb bare metal loadbalancer — AdminTome Blog

Mining App FAQ

Announcing Eleven Finance x Wault Finance Partnership!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Deploying a Flask App to Heroku with MongoDB using QuotaGuard

How to build GUI Application with PYQT

How To Create A Dynamic GitHub Badge Using Flask, Heroku and service: Part Two.

Build a simple URL Shortener service like bitly!

URL shortener image