I have created a table employee_details as below and then with two api's to add a new user and other to show all users as:
from flask import Flask,jsonify,request
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:root@localhost/empdb'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=False
db=SQLAlchemy(app)
ma = Marshmallow(app)
class employee_details(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    empid = db.Column(db.Integer)
    ename = db.Column(db.String(80), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    city = db.Column(db.String(120), unique=True, nullable=False)
    department = db.Column(db.String(120), unique=True, nullable=False)
    def __init__(self,empid, ename, email,city,department):
        self.ename = ename
        self.email = email
        self.empid=empid
        self.city=city
        self.department=department
class EmpSchema(ma.Schema):
    class Meta:
        fields = ('ename', 'empid','city','department')
emp_schema = EmpSchema()
emps_schema = EmpSchema(many=True)
db.create_all()
@app.route("/emp", methods=["POST"])
def add_emp():
    empid=request.json['empid']
    ename = request.json['ename']
    email = request.json['email']
    city=request.json['city']
    department=request.json['department']
    new_emp = employee_details(empid,ename, email,city,department)
    db.session.add(new_emp)
    db.session.commit()
    return emp_schema.jsonify(new_emp)
@app.route('/emp',methods=['GET'])
def show_emps():
    all_emps=employee_details.query.all()
    result=emps_schema.dump(all_emps)
    return jsonify(result)
if __name__=='__main__':
    app.run(debug=False)
How can write another api to show that particular employee detail based on email in json(email sent from POSTMAN not a form)? I tried as :
@app.route('/getemp',methods=['GET','POST'])
def get_emp():
    email=request.json['email'] #trying to get email from POST (from postman)
    emp=employee_details.query.filter_by(email=email).first() #filter and get whole details
    return jsonify(emp)
which doesn't work and I guess its wrong way!! any help for this noob question is appreciated
 
    