RESTful APIs for CRUD, file upload and JWT token based Authentication using Flask and SqlAlchemy ORM
Flask_SqlAlchemy_APIs is a backend application which serve API's for basic CRUD
operation, uploading file and JWT token based user authentication. It is built using most lightweight framework flask
and one of popular Object Relation Mapper SqlAlchemy
. I have used mysql
as database in this app.
- Python
- Flask
- SqlAlchemy
- Postman
- Add Admin.
- Get information for all Admins in database.
- Get information for admin with specific id.
- Update Admin Information.
- Delete Admin from Database.
- Upload file.
- User Authentication using
JWT
token.
- We need to send
POST
request through postman and provide payload in Body section.
{
"email": "sakangupt@gmail.com",
"phone": " 7788990011",
"full_name": "Sakshi Gupta",
"password" : "Pass@123",
"role": "Admin",
"status": "Active"
}
- We simply need to call http://127.0.0.1:5000/all_admin/ this endpoint with
GET
request to get JSON data. - Image for reference :-
- We need to pass
id
at end of URL withPUT
request. - Example :- http://127.0.0.1:5000/admin/101 . Here
101
isid
ofSuper Admin
. - Image for reference :-
- We need to pass
id
at end of URL and payload along withPUT
request. - Example :- http://127.0.0.1:5000/admin/104 .
- Payload will be :-
{
"full_name": "Swaraj Gore",
"email": "swarajgo@gmail.com",
"password" : "Pass@1234",
"phone": "49857243857",
"role": "Admin",
"status": "Active"
}
- We need to pass
id
at end of URLDELETE
request. - Example :- http://127.0.0.1:5000/admin/3 .
- Image for reference :-
- This will be
POST
request and in postman under body section pass appropriate parameters as shown in below image. - Example :- http://127.0.0.1:5000/upload_file .
- Image for reference :-
- In this case we will perform two operations:-
- Getting
JWT token
. - View all admins list with token.
- Getting
- This will be
POST
request and in postman under body section pass credential payload as shown in below image. - Example :- http://127.0.0.1:5000/admin_login .
- Image :-
- Now you got
JWT token
by calling this endpoint.
- This will be get request, But you need to provide
Bearer token
inAuthorization
section. Which you got from above step. - Example :- http://127.0.0.1:5000/all_admin .
- Image :-
- You will get JSON data of all admin, if everything goes well.
- Clone Repo https://github.com/cartosat/Flask_SqlAlchemy_APIs.
- Database Setup :-
- Install MySQL Community (GPL) version for mysql database.
- execute
virtual_studio.sql
to automatically create database.
- Postman Setup :-
- Install PostMan.
- Import
AppBackend.postman_collection,json
collection.
- Python Setup :-
- Install Python.
- Install
requirement.txt
withpip install -r requirement.txt
.
- Call API's using postman.