Skip to main content

Django-based REST API Framework

Project description

# Rinzler REST Framework

Django-based REST Micro-Framework

# Install requires

```PHP
pip install rinzler
```

# Usage
```Python

# urls.py

import os
import rinzler

from rinzler.core.main_controller import MainController
from your_controller import Controller

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

app = rinzler.boot(BASE_DIR)
assembler = app['url_assembler']

urlpatterns = [
assembler.mount('hello', Controller),
assembler.mount('', MainController),
]

```

```Python
# your_controller.py
from collections import OrderedDict

from django.http.request import HttpRequest
from django.views.generic import TemplateView

from rinzler.core.response import Response


class Controller(TemplateView):

def connect(self, app):

router = app['router']

# map end-points to callbacks here
router.get('/world/', self.hello_world)
router.get('/{name}/', self.hello_user)

return app

# end-point callbacks here:
@staticmethod
def hello_world(request: HttpRequest, app: dict(), **params: dict):
"""
Default route callback
:param request HttpRequest
:param app Rinzler's object
:param params dict url params, if present
:rtype: Response
"""
try:
response = OrderedDict()
response["status"] = True
response["data"] = "Hello World!"

return Response(response, content_type="application/json")
except BaseException as e:
response = OrderedDict()
response["status"] = False
response["mensagem"] = str(e)

return Response(response, content_type="application/json", status=500)\

@staticmethod
def hello_user(request: HttpRequest, app: dict(), **params: dict):
"""
Default route callback
:param request HttpRequest
:param app Rinzler's object
:param params dict url params, if present
:rtype: Response
"""
try:
user = params['name']
response = OrderedDict()
response["status"] = True
response["data"] = "Hello {0}!".format(user)

return Response(response, content_type="application/json")
except BaseException as e:
response = OrderedDict()
response["status"] = False
response["mensagem"] = str(e)

return Response(response, content_type="application/json", status=500)

```
### Run django
```shell
python manage.py runserver
August 02, 2017 - 18:48:00
Django version 1.10.4, using settings 'Demo.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
```

### Sample requests

```shell
curl http://localhost:8000/
<center><h1>HTTP/1.1 200 OK RINZLER FRAMEWORK</h1></center>

curl http://localhost:8000/hello/world/
{
"status": true,
"data": "Hello World!"
}

curl http://localhost:8000/hello/bob/
{
"status": true,
"data": "Hello bob!"
}

curl http://localhost:8000/foo/bar/
{
"status": false,
"exceptions": {
"message": "No route found for GET foo/bar/"
},
"request": {
"content": "",
"method": "GET",
"path_info": "foo/bar/"
},
"message": "We are sorry, but something went terribly wrong."
}

```


Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rinzler-1.22.0-py2.py3-none-any.whl (16.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file rinzler-1.22.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for rinzler-1.22.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 efa7398ad8585017e45064506f1bfc8dff74340b549e8f940381f662c822c196
MD5 102f330cbc221454bfc171cb1b9afbef
BLAKE2b-256 f278b42b695bdfaaff45573a68e488a47d941b637410405a7e12a838b1ce6191

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