DEV Community

Max Ong Zong Bao
Max Ong Zong Bao

Posted on • Edited on

Building Restful API with Flask, Postman & PyTest - Part 1(Read Time: 6 Mins)

Photo by Christopher Burns on Unsplash

Introduction

For the first part of the 3 part series of the building Restful API with Flask, Postman and PyTest.

I will be covering the explanation of the libraries and tools used to create a expenses manager project based upon Testing Python Applications with Pytest so that you will understand why you might use these tools or libraries as part of your development process to develop APIs in Flask.

Whereas in part 2 of the series, I will cover the API design of the expenses manager and mocking API endpoints in Postman.

Finally, for part 3 we will be implementing the API in flask with test cases built using PyTest.

Journey from a Django Developer to an API Developer

When I first started to become a Django developer, I learnt the basics on how to build a basic website with Django, SQL Database and JQuery.

As I grow in experience, I realised the importance of building single page web apps by using front-end frameworks with Django as backend.

I learnt to combine my understanding of front-end framework from Udacity with Django Rest framework to develop APIs for the front-end to consume for my backend during my work.

Building APIs using Flask

Flask is another python based web framework that is considered the go to framework for developing Restful APIs.

I had come across multiple articles or sources in freeCodeCamp due to its flexibility & simplicity to create APIs without much effort.

Coming from experience using Django Rest Framework, I was quite sceptical of it when I first started to use it.

With time flask wins me over but due to flask's flexibility, it can be painful in learning.

Due to the reason that there is no one specific way in building an API compared to Django Rest Framework.

Mocking & Testing Using Postman

While building APIs, I started to use tools that allow me to test my API at a much faster pace.

One of these tools is Postman, which I used it as a testing tool and API documentation for my front-end developer initially.

But I found out later that you can break the interdependence problem of front-end and backend through using the Postman's mock server feature.

Breaking API Dependence Workflow of Frontend & Backend.

With Postman's mock server, a front-end developer can focus on integrating mock endpoints without relying on the backend.

Whereas for the backend developer, they could focus on providing the front-end with a working endpoint and swap it around when it has completed. Further reducing the time to ship for the development team.

Creating Test Cases with PyTest

PyTest is my goto testing framework in python as it is easy to learn and has lesser boilerplate code compared to the default installed unittest library.

Which follows the JUnit style of implementation which could be intimating when you first started to use.

Conclusion

I hope the first part of the series explains the rationale on using tools or libraries like Postman and Pytest can help in speeding up the development process.

Please stay tuned for part 2 and part 3 of the series to teach you on how to create mock endpoints and implement it in Flask with test cases in Pytest.

Links

If you like my article either sign up for Max's Weekly Newsletter or you can follow to get the latest update of my article on Dev

This post was originally posted on max's blog at Building Restful API with Flask, Postman & PyTest - Part 1 and picture from Photo by Christopher Burns on Unsplash

Top comments (0)