Photo by Ciprian Boiciuc on Unsplash

How to make a simple API for generating random names and emails using Flask.

This article is for the beginner who is looking to create an API using the flask. We will be creating an API that can return a random name and email for every request that reaches the API.

Let's build an API!!

  1. Build the application.
  2. Deploying the application.

Check if the flask is installed and working fine, make a file called hello.py with the following code.

And run the following code in the path where the file is created.

You will get the response

Then you can confirm that your application is running checking the URL http://localhost:5000/ in your browser and can see Hello World.

To begin, we are going to be using the command line to build out a folder and make files for our application.

  1. Create a new folder called flask_api

2. Create a new file called server.py within the flask_api folder

3. Copy paste the following code to server.py.

Running the server

  1. Save your server.py file
  2. In a terminal navigate to your flask_api folder
  3. Enter command python server.py to run server
  4. Navigate to http://localhost:5000 in your web browser
  5. You are now running your own server locally!

you can find the random name and email JSON response in the browser on navigating to http://localhost:5000 example:

The source code for the current application is provided in my GitHub.

Next Steps

We have done the coding part for our application. The continuation parts of this post will be showing you how to deploy this application.

Next things we are going to do:

  1. Get a Heroku account.
  2. Add your code to GitHub.
  3. Deploy your application to Heroku.

Please provide your feedback and suggestions. Follow me to get the latest updates.

Linkedin: linkedin.com/in/joel-hanson/

Portfolio: joel-hanson.github.io/

Github: github.com/Joel-hanson

Twitter: twitter.com/Joelhanson25

Works at @impressAI

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