This is an API that enable users to GET data about surveys from a database or POST new surveys.
- Clone the repository locally.
- Download dependencies:
pip install -r requirements.txt
. - Create a local relational database using the DB interactive shell (I use PostgreSQL).
- Modify credentials and/or database URI in
db_credentials.py
. - Setup the database:
python db_setup.py
. - Run the application:
python app.py
Anyone can GET
data from /survey
but only registered users can POST
new surveys.
-
registration:
POST
a JSON containingusername
andpassword
to/register
.
example:curl -X POST 'http://127.0.0.1:5000/register' -H 'content-type:application/json' -d '{"username":"Amr", "password":"123"}'
-
getting a token:
use your credentials toGET
an authorization token from/token
.
example:curl -u "Amr":"123" 'http://127.0.0.1:5000/token'
.
tokens expire in 15 minutes. get a new token when yours expire. -
creating new surveys:
use your token toPOST
a new survey to/survey
.
example:curl -u "<token>":"blank" 'http://127.0.0.1:5000/survey' -H 'content-type:application/json' -d '{"name":"My Survey", "start_date":"13/10/2019 04:00", "questions":[{"question":{"body":"Do you like my API?"}}]}'
Note: errors in you requests are handeled and you will get JSON feedback with the errors
if any or success
in case of no errors.