A RESTful API with JWT user authorization to be used for creating, taking and viewing surveys.
- Image thumbnail generation endpoint
- Flask
- Pillow
- sqlite3
- JWT
Run pip install -r requirements.txt
to install required dependencies.
-
- Usage: /survey/create
- Method: POST
- Function: Used to create survey
- Sample:
{ "name": "College students survey", "questions": [ { "qid": 1, "qbody": "Are you a CompSci Student?" }, { "qid": 2, "qbody": "Do you own a bike?" } ] }
- Respone:
{ "OK": "Survey 'College students survey' created" }
-
- Usage: /survey/take/<survey_id>
- Method: POST
- Function: Used to take a survey
- Sample: assume /survey/take/1
{ "qid": 1, "answer": "yes" }
- Response:
{ "OK": "Question 1 answered" }
-
- Usage: /survey
- Method: GET
- Function: Used to view all surveys
- Output:
{ "": [ "Survey: College students survey", "Question: Are you a CompSci student?", "Answer: yes", "------------------", "Question: Do you own a bike?", "Answer: Not answered", "------------------" ] }
-
- Usage: /login
- Method: POST
- Function: Used to login and get JWT
- Sample:
{ "username": "user", "password": "mypass" }
- Response:
{ "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InVzZXIiLCJwYXNzd29yZCI6Im15cGFzcyJ9.Tal2QcuQ_OST1KbZA12W6oyBs3ojksGiUozU-u0gxrs" }
-
- Usage: /thumbnail/<impage_url>
- Method: GET
- Function: Downloads image from the url, resizes it to 50x50 pixel image, stores it locally
- Output: creates image.extention(Original Image) and resized.extention(Resized Image) in current directory
{ "OK": "Image successfully resized" }
Use postman (or similar application) and start with /login
to generate a token
After copying token and adding it as a value of 'custom-token-header', use the application as described in this file