Flask-RESTful is an extension for flask that adds supports for quickly building REST APIs.
- Install required depencies using
pip install -r requirements.txt
- Download Postman for testing api Postman
- Run sqlscript.py to create login and employee table and populate sample data.
- Start the app by running run.py from command prompt or terminal
python run.py
- Open Postman and enter url http://0.0.0.0:5000/employee/api/v1.0/all, In authorization tab, select basic auth and enter username and password. Hit send button to get all the employee data.
- To add one or more employee data enter url http://0.0.0.0:5000/employee/api/v1.0/all, In authorization tab, select basic auth and enter username and password. Under body tab, select raw and change data as JSON(application/json) and enter data in below format.
Sample data for adding two employee data.
{ "employee": [ { "employee_name": "Rohan", "employee_sal": 10001 }, { "employee_name": "Ram", "employee_sal": 15001 } ] }
- Repeat step 5 to view data.
- You can also build docker image using dockerfile which will setup all pre-requisite.
docker build . -t <image name>
- Run docker image usin below command
docker run -p 5000:5000 <image name>
In case you want to detach terminal then use below command
docker run -d -p 5000:5000 <image name>
- Repeat step 5
Note: If you're using docker-toolbox, then you might need to use below command to get the IP.
docker-machine ip default