Lets talk about these files briefly :
data.sqlite: As I already discussed I have used Sqlite database for this rest api because it is portable and it remove the dependency to setup new database. This data.sqlite file is our database file which is connected using SQLAlchemy.
models.py: This file contains our database table details, In this file we can change our table structures like add new fields , remove existing one and add other validation properties.
settings.py: This is our settings file where we can define configurations of our application like define our database setting and debug settings. In this file I have defined two paths for linux as well as for windows os. Currently I have commented windows path and used linux path. If you are using window just uncomment it.
myapp.py: This is core file of our api which will handle all the CRUD operation on specific url with specified Http request method. I have created methods for handling Http request and performing CRUD operations.
requirement.txt: This is file contains dependencies information to run this project.
- Python 3.6+
- Flask
- postman
- How to build rest Api in Flask
- Create database with Flask using SQLAlchemy
- Handling CRUD Operations
- clone or download it from here
- install requirements.txt file
pip install -r requirements.txt
- run this command to execute this code
python myapp.py
When it runs your temrminal/cmd will be like above image
- For fetching all user records, Just browse this url in your browser http://0.0.0.0:5000/user
- For creating new user with post request using postman