Simple Web API in Python

Hello everyone, Welcome back! In this blog, we will learn writing a simple Web API which serves JSON in Python programming language. We will use Flask Library to create web API’s in Python. So go ahead, and install Flask using pip.

prerequisite

Now that we have our library, let’s go ahead and start writing our own python code, to return a JSON on a request made to our localhost i.e. 127.0.0.1 on port 5000. Following is the Python code, beautified using carbon.now.sh.

Python Code for a Simple Web API

That’s too simple in Python. Run this python file from your terminal, and go ahead to your favorite browser, and browse this url. You should see the JSON being displayed on your browser, to beautify install JSON extension to your browser.

result JSON on browser

This JSON is now being served on your localhost at port 5000, and front end applications can make use of it to render in a beautiful way. That’s it for this blog, a simple & shorter one . Meet you on my next blog. Until then stay safe. Cheers ✌

Leave a comment

Design a site like this with WordPress.com
Get started