I am new to Python/Falcon. How to get employee details by userId
in Python?
falcontry.py
Falcon example:
import falcon
import json
class ThingsResource:
def on_get(self, req, resp):
resp.status = falcon.HTTP_200
fp = open("jsonparser.json","r")
json_str = fp.read()
print json_str json_content = json.loads(json_str)
json_content = json.dumps(json_content)
print json_content resp.body = (json_content)
api = falcon.API()
things = ThingsResource()
api.add_route('/Employees/userId/{id}', things)
what i am doing wrong here?
jsonparser.json Employees:
{ "Employees" : [{
"userId":"RUPAK",
"jobTitleName":"Developer",
"firstName":"ABC",
"lastName":"Irani",
"preferredFullName":"Romin Irani",
"employeeCode":"E1",
"region":"CA",
"phoneNumber":"408-1234567",
"emailAddress":"[email protected]"
}]
}
Your JSON/Dict:
Employees Class:
Output:
$ python pytest.py {'emailAddress': '[email protected]', 'phoneNumber': '408-1234567', 'jobTitleName': 'Developer', 'firstName': 'ABC', 'lastName': 'Irani', 'preferredFullName': 'Romin Irani', 'employeeCode': 'E1', 'userId': 'RUPAK', 'region': 'CA'}
Let me know if you need more details on the approach. As it stands, it is pretty hard to understand what you are looking for, because of the lack of information/formatting in your question.
Hope it helps you!