This server uses python 3.4
using virtualenv:
virtualenv -ppython3
pip install -r <path_to_project>/requirements.txt
This is the basic architecture for an API which provides a dynamic model framework and it's dynamically built relative REST endpoints. It's called Middle Man due lack of creativity.
The server consists in two parts: api and application.
The api API will enable the developer to create dynamic models, assigning types to a specified project. This API will be accesed through a REST interface based on common username/password authorization.
python manage.py runserver
Root endpoint:
/api/v1/
Enabled endpoints:
Registers a new user: POST { "name" : "John", "email" : "[email protected]", "password" : "pocorn123" }
logs in a user: POST { "email" : "[email protected]", "password" : "pocorn123" }
logs out a user.
Creates a new project:
POST { "name": "MyProject" }
Lists all projects associated by a user:
GET
{
"projects": [
{
"access_token": "20ab121ba0722f2c",
"id": "eAx5236pZJ",
"name": "MyProject"
}
]
}
Lists all models associated by a project:
GET /api/v1/projects/eAx5236pZJ
{
"access_token": "dc55415aed5651e4",
"models": [
{
"attributes": [
{
"attrtype": "STRING",
"id": "eAx5236pZJ",
"name": "name"
}
],
"name": "Product"
}
],
"name": "MyProject2"
}
Adds models to a project:
POST /api/v1/projects/eAx5236pZJ/models
{
"models": [
{
"attributes": [
{
"attrtype": "STRING",
"name": "name"
}
],
"name": "Product"
}
]
}
Updates a model:
POST /api/v1/projects/eAx5236pZJ/models/eAx5236pZJ
{
"attributes": [
{
"attrtype": "STRING",
"name": "new_attribute"
}
]
}
Deploys a project. Will create all databases associated with each model.
POST /api/v1/projects/eAx5236pZJ/deploy
200 OK
Undeploys a project. Will drop all databases associated with each model.
POST /api/v1/projects/eAx5236pZJ/undeploy
200 OK
The application API will create common endpoints based on the specified models and provide basic authorization through an Access Token associated with the project.
the endpoints will be accessed through this pattern:
Root endpoint:
/api/v1/apps/
Enabled endpoints for a specific app:
GET /<model_name> - Fetches alls models
GET /<model_name>/{id} - Fetches a model by id
POST /<model_name> - Creates a new model
PUT /<model_name>/{id} - Edit a model
DELETE /<model_name>/{id} - Deletes a model
All acesses are validated through the X-Internal-AccessToken header, which can be recovered through the administrative API.
-
The application and the administration interface are running in the same server. This can be easily modified to specify different servers. Also, all projects are on the same structure, which can be modified to enable per application as well (on the case that the developer wants to run the model on his own server)
-
The database models are created dynamically every time the server starts. This can be improved.
-
There is no fine-grained acccess control.
-
Database errors are not properly handled on application endpoint.
- Basic system structure
- Models
- Administrative
- Application
- Controllers
- Admin interface
@copyright Victor Vicente de Carvalho, 2015