Skip to main content

Django application. To launch an api server without endpoint. Create the database on demand

Project description

# django-themagicapi

Django application. To launch an api server without endpoint.
Create the database on demand.

We can create multiple databases for different applications.
Just focusing on the client.

According to how we do the JSON query the server.
It will create, alter the table, insert,
list or delete data from an entire database automatically.

Requirements
------------
* Django 1.5+
* django-tokenapi
* valleorm
* django-cors-middleware

Installation
------------

First obtain `themagicapi` package and place it somewhere on your PYTHONPATH, for example
in your project directory (where settings.py is).

Alternatively, if you are
using some sort of virtual environment, like [virtualenv][], you can perform a
regular installation or use [pip][]:

python setup.py install

# or ...

pip install django-themagicapi

[virtualenv]: http://pypi.python.org/pypi/virtualenv
[pip]: http://pip.openplans.org/

Add 'themagicapi', 'tokenapi' and 'corsheaders' to your `INSTALLED_APPS`.

###These are the modifications of settings.py file:
```python
#Add these lines
PATH_DBS = os.path.join(BASE_DIR, "[path-of-databases]/")

MEDIA_ROOT = os.path.join(BASE_DIR, 'docfiles')
MEDIA_URL = '/docfiles/'

INSTALLED_APPS = [
'themagicapi.apps.ThemagicapiConfig',
'corsheaders',
#......
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware'
#......
]

AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'tokenapi.backends.TokenBackend'
#.....
]

CORS_ORIGIN_ALLOW_ALL = True
```

Include `themagicapi.urls` and `tokenapi.urls` in your `urls.py`.
It will look something like this:

urlpatterns = [
url(r'^token/', include('tokenapi.urls')),
url('', include('themagicapi.urls')),

]

Configuration and usage of token
--------------------------------

You can change the number of days that a token is valid for by setting
`TOKEN_TIMEOUT_DAYS` in `settings.py`. The default is `7`.
more information see [django-tokenapi]: https://github.com/jpulgarin/django-tokenapi.git

Usage
-----
### Create new table user if not exists and add new user.
paramsRow = {
'add':{
"db":"valleorm.db",
'user':{
"nombre": "Pepito",
"apellido": "Lopez",
}
}
}

### Modify a user with know ID. Alter table automatically.

paramsRow = {
'add':{
"db":"valleorm.db",
'user':{
'ID': 1,
'apodo': 'donpepito',
'telf': '666666'
}
}
}

### Get all user

paramsRow = {
'get':{
"db":"valleorm.db",
'user':{
}
}
}

### Get by ID

paramsRow = {
'get':{
"db":"valleorm.db",
'user':{
'ID': 1,
}
}
}

### Remove row by ID
paramsRow = {
'rm':{
"db":"valleorm.db",
'user':{
'ID': 1,
}
}
}


For more requests see [themagic-apiserver]: https://github.com/vallemrv/themagic-apiserver.git

Requests example
----------------
```python
import requests
import json
data = json.dumps(***someparams***)
#for get token see https://github.com/jpulgarin/django-tokenapi.git
token = {
'user': 1, #user number
'token': 'some token',
'data': data
}

r = requests.post("http://localhost:8000/", data=token)
print r.json()

```
:scroll: License
----------------

Licensed under the Apache-2.0, see `LICENSE`

:heart_eyes: Contributors
--------------------------

Manuel Rodriguez <valle.mrv@gmail.com>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-themagicapi-1.0.34.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file django-themagicapi-1.0.34.tar.gz.

File metadata

File hashes

Hashes for django-themagicapi-1.0.34.tar.gz
Algorithm Hash digest
SHA256 c467ad2b62b82a6496a622c4194ea975c945768a9ab1f9d7b8fda88ea4e6ecd1
MD5 c0ff99aca319b265e5566d47aa484403
BLAKE2b-256 44bdb6104c6f93dea66a22a4047ad128f9c32032d390040297a8338438582dee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page