Above code contains a sample GET and POST call to show the working of Flask API GET call recieves data from a file present in server and POST call saves a file sent to the server.
To Run this code:
- Just enter command
python3 flask_simplified.py
This will start the server (Mind it. This is Flask's internal dev server. Don't use it for production) - On a different terminal , go inside sourceFiles directory and run the following cURL commands to trigger GET and POST command.
(GET command can be triggered from anywhere in new terminal but for POST , since we require files, so , it has to be triggered in sourceFiles directory):
curl localhost:5000/getJsonFromFile/labelsFile.txt
- Observe the response recieved. It should give labels_mapping:{"keyvalue pair of labels and numbers}
- In case the file is not found , you should get error:"error_statement" as the response.
- Then trigger following cURL command (in sourceFiles Directory)to test POST request :
curl -F "FILES_LIST=@./file1.jpg" -F "FILES_LIST=@./file2.jpg" -F "FILE_NAME=new_file" localhost:5000/uploadFiles
You should get "STATUS":"true" as response and check in directory where flask_simplified.py file is present, the new files should be generated.