A simple Flask REST API to store, fetch, and update user/group records. Based off of specifications in code_test. Uses SQLite as its datastore. Written/tested with python 2.7.
After cloning the repository into a virtualenv, change into the project's root directory and install the requirements with:
pip install -r requirements.txt
The database can be initialized in the project's root, and an initial migration run, using:
python manage.py deploy
You're all set.
To verify your installation, the unit tests can be run using:
python manage.py test
The local web server can be run, on http://localhost:5000
, using:
python manage.py runserver
Note: in this implemenation, a user only requires the userid
field, and a group the name
field.
Returns JSON
object. Succesful responses will return user representation inside the result
attribute. Non 200
responses will contain an error
attribute.
Expects user information, with the following fields:
{
"first_name": "Joe",
"last_name": "Smith",
"userid": "jsmith",
"groups": ["admins", "users"]
}
Accepts either a JSON
payload, in the format above, or standard form data. userid
is required. Succesful responses will return {"result": true}
. Non 200
responses will contain an error
attribute.
Expects user information, with the following fields:
{
"first_name": "Joe",
"last_name": "Smith",
"groups": ["admins", "users"]
}
Accepts either a JSON
payload, in the format above, or standard form data. Replaces current user info with new data. Succesful responses will return {"result": true}
. Non 200
responses will contain an error
attribute. Will return 404
if user doesn't already exist.
Succesful responses will return {"result": true}
. Non 200
responses will contain an error
attribute. Will return 404
if user doesn't already exist.
Returns JSON
object. Succesful responses will return a list of userid's inside the result
attribute. Non 200
responses will contain an error
attribute.
Expects group information, with the following fields:
{
"name": "admins"
}
Accepts either a JSON
payload, in the format above, or standard form data. name
is required. Succesful responses will return {"result": true}
. Non 200
responses will contain an error
attribute.
Expects a list of userids:
{
"userids": ["jsmith"]
}
Accepts either a JSON
payload, in the format above, or standard form data. userids
is required. Replaces current users with the new list. Succesful responses will return {"result": true}
. Non 200
responses will contain an error
attribute. Will return 404
if group doesn't already exist.
Succesful responses will return {"result": true}
. Non 200
responses will contain an error
attribute. Will return 404
if group doesn't already exist.