A Flask-API to handle publications of research data. After a new publication workflow is started with a new publication (POST /publications), curators can add, change or delete feedback to the publication. Authors can mark these feedbacks as done and give their ok to the publication according to an external checklist. After all feedback is done by the authors, administrators can then publish the publication and export it afterwards to the bibliography.
This is a slimmed down version of a Dataverse compatible publishing workflow, submitted as a Capstone project to Udacity
Contact information:
fokus@izus.uni-stuttgart.de
License: MIT
Follow instructions to install the latest version of python for your platform in the python docs
We recommend working within a virtual environment whenever using Python for projects. This keeps your dependencies for each project separate and organaized. Instructions for setting up a virual enviornment for your platform can be found in the python docs
Once you have your virtual environment setup and running, install dependencies by naviging to the /backend
directory and running:
pip install -r requirements.txt
This will install all of the required packages we selected within the requirements.txt
file.
-
Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.
-
SQLAlchemy is the Python SQL toolkit and ORM we'll use handle the lightweight sqlite database. You'll primarily work in app.py and can reference models.py.
-
Flask-Migrate is an extension that handles SQLAlchemy database migrations for Flask applications using Alembic.
-
PyJWT is a Python library which allows you to encode and decode JSON Web Tokens (JWT).
From within the backend
directory first ensure you are working using your created virtual environment.
To run the server, execute:
flask run
From the /tests-Directory, run
python -m unittest
The trivia-API functions as a backend for the trivia-frontend. It offers endpoints to get available questions (also per category), add new questions and deliver random questions for the game.
The API consumes and returns JSON-Objects. Status code for successful API-Requests is always 200. Every answer object includes a success attribute with the value True if the request can be responed successful and the value False in case of an error.
Error Objects have the following structure:
{
'success': False,
'error': <status-code, for example 404>,
'message': '<errormsg, for example _file not found_>'
}
Expectable Errors:
Status Code | Error message | Explanation |
---|---|---|
400 | bad request | a required parameter was not supplied |
401 | unauthorized | you did not authenticate successfully against the service |
403 | forbidden | authentication was successfull, but you do not have the required permission |
404 | resource not found | the resource you requested is not available, for example a non existing endpoint, a non existing publication or a non existing feedback |
405 | method not allowed | the method (GET, POST, PUT, PATCH, DELETE) you used is not supported by the endpoint |
409 | conflict | request asks for something inconsistent, for example a feedback with a inconsistent publication or a workflow step that is noch allowed in this status |
422 | not processable | the request could not be processed |
500 | internal server error | an error on server side prevented the response to the request |
The API uses JSON Web Tokens (JWT) for Authentication. As a registered user, you can get or renew your Token with the GET /token/string:identifier Endpoint, using your identifier.
Add this token as a bearer token to the "Authorization"-Header.
Authorization: bearer <token>
adds new user
Code | Description | Schema |
---|---|---|
200 | success | object |
400 | required information missing | |
422 | unprocessable, user could not be added |
get (new) JSON Web Token for authentication
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
identifier | path | identifier of registered user | Yes | string |
Code | Description | Schema |
---|---|---|
200 | success | object |
400 | required information missing | |
401 | authentication missing | |
403 | not allowed, required permission missing | |
422 | unprocessable, user could not be added |
gets all available publications
Code | Description | Schema |
---|---|---|
200 | success | object |
401 | authentication missing | |
403 | not allowed, required permission missing |
add a new publication
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
publication | body | The publication to create | No | Publication |
Code | Description | Schema |
---|---|---|
200 | success | object |
400 | required information missing | |
401 | authentication missing | |
403 | not allowed, required permission missing | |
422 | unprocessable, user could not be added |
get the publication with id {pid}
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
pid | path | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | success | object |
400 | required information missing | |
401 | authentication missing | |
403 | not allowed, required permission missing | |
422 | unprocessable, user could not be added |
deletes the publication with id {pid}
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
pid | path | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | success | object |
401 | authentication missing | |
403 | not allowed, required permission missing | |
404 | publication not found | |
422 | unprocessable, publication could not be deleted |
indicates, that author has finished checklist
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
pid | path | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | success | object |
401 | authentication missing | |
403 | not allowed, required permission missing | |
404 | required information missing | |
409 | WorkflowError, giving ok to already published or exported publication | |
422 | unprocessable, user could not be added |
publishes a data publication
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
pid | path | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | success | object |
401 | authentication missing | |
403 | not allowed, required permission missing | |
404 | required information missing | |
409 | WorkflowError, giving ok to already published or exported publication | |
422 | unprocessable, user could not be added |
exports a data publication
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
pid | path | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | success | object |
401 | authentication missing | |
403 | not allowed, required permission missing | |
404 | required information missing | |
409 | WorkflowError, trying to export publication that is not published | |
422 | unprocessable, user could not be added |
returns all feedback for publication with id {pid}
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
pid | path | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | success | object |
401 | authentication missing | |
403 | not allowed, required permission missing | |
404 | publication not found |
adds a new feedback to publication with id {pid}
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
pid | path | Yes | integer | |
feedback | body | No | FeedbackShort |
Code | Description | Schema |
---|---|---|
200 | success | object |
400 | text is missing in JSON-Body | |
401 | authentication missing | |
403 | not allowed, required permission missing | |
404 | publication not found | |
422 | unprocessable, feedback could not be saved in database |
gets a specific feedback
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
pid | path | ID of the publication | Yes | integer |
fid | path | ID of the feedback | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | success | object |
401 | authentication missing | |
403 | not allowed, required permission missing | |
404 | publication or feedback not found | |
409 | conflict, feedback does not belong to publication |
changes the text of a specific feedback
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
pid | path | Yes | integer | |
fid | path | ID of the feedback | Yes | integer |
feedback | body | No | FeedbackShort |
Code | Description | Schema |
---|---|---|
200 | success | object |
400 | required information missing | |
401 | authentication missing | |
403 | not allowed, required permission missing | |
404 | publication or feedback not found | |
409 | conflict, feedback does not belong to publication | |
422 | unprocessable, feedback could not be updated |
marks a feedback as done
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
pid | path | Yes | integer | |
fid | path | Yes | integer |
Code | Description | Schema |
---|---|---|
200 | success | object |
400 | required information missing | |
401 | authentication missing | |
403 | not allowed, required permission missing | |
404 | publication or feedback not found | |
409 | conflict, feedback does not belong to publication | |
422 | unprocessable, feedback could not be updated |
Name | Type | Description | Required |
---|---|---|---|
id | integer | Yes | |
invocationId | string | Yes | |
doi | string | Yes | |
displayName | string | Yes | |
status | string | No | |
okAuthor | dateTime | No | |
published | dateTime | No | |
exported | dateTime | No |
Name | Type | Description | Required |
---|---|---|---|
id | integer | Yes | |
text | string | Yes | |
done | boolean | Yes | |
publication | Publication | No | |
author | Role | No |
Name | Type | Description | Required |
---|---|---|---|
text | string | Yes |
Name | Type | Description | Required |
---|---|---|---|
id | integer | Yes | |
name | string | Yes | |
identifier | string | No | |
roles | [ string ] | No |