My coding flow for Back-end development in Python🐍
I'm thrilled to give you a peek inside my experience learning API code for my working project in Python today. Python's ease of use and adaptability have to find a variety of jobs and projects.
In my learning stage, I found that there are 3 main files that hold the backend flow.
Step 1: Create a server for project
I used the Flask package (one of the libraries of python) to create and run the server on localhost as below
Step 2: Connect the database with the server
I am using the MySQL database for working with data. You can use any other database such as Firebase, Mongodb, or MariaDB. Python supports almost every database.
Then I create a route.py file to generate and establish my API using Flask library. I wanted to create a path like http://localhost:5000/api/users/add_user. For this flow, I need to register/api first and it was registered in the server file. After that I registered /api/users/add_user as below.
During running any backend logic, first of all, we need to handle unexpected errors that may be generated during the execution of the server. We can use Try and Expected flow to handle errors.
Recommended by LinkedIn
The final step is to write a logic code in Python that will handle the actions according to API calls. For example, I try to add form data into the database. First I check if the data already exists in a database or not. If the data is exited then it will be said the data is already exited, otherwise, it will insert data into the database.
These are all basic knowledge that I learned in the process of creating the back end in Python. I created this flow to solve complexity in code which has helped me to handle errors and flow. I hope it will be helpful for you.
Thank you for reading.