Skip to main content

Rinzler REST Framework

Django-based REST Micro-Framework

Install requires

pip install rinzler

Usage

# urls.py
from rinzler import boot, Rinzler

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


app: Rinzler = boot("MyApp")

urlpatterns = [
    app.mount('hello', Controller),
    app.mount('', MainController),
]
# your_controller.py
from django.http.request import HttpRequest

from rinzler import Rinzler
from rinzler.core.response import Response


class Controller:

    def connect(self, app):

        router = app.get_end_point_register()

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

        return router

    # end-point callbacks here:
    @staticmethod
    def hello_world(request: HttpRequest, app: Rinzler, **params: dict):
        """
        Default route callback
        :param request HttpRequest
        :param app Rinzler's object
        :param params dict url params, if present
        :rtype: Response
        """
        try:
            response = {
                "status": True,
                "data": "Hello World!",
            }
            return Response(response, content_type="application/json")
        except BaseException as e:
            response = {
                "status": False,
                "mensagem": str(e),
            }
            return Response(response, content_type="application/json", status=500)\

    @staticmethod
    def hello_user(request: HttpRequest, app: Rinzler, **params: dict) -> Response:
        try:
            user = params['name']
            response = {
                "status": True,
                "data": f"Hello {user}!",
            }

            return Response(response, content_type="application/json")
        except BaseException as e:
            response = {
                "status": False,
                "mensagem": str(e),
            }
            return Response(response, content_type="application/json", status=500)

Run django

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

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."
}
# If project's settings has DEBUG=True, otherwise: empty response body with status-code 404

Authentication

Authentication can be done on a per-route basis thus allowing to have authenticated and non-authenticated routes on the application.

To do so, first you need to create a class that inherits from BaseAuthService and implements the authenticate method.

from django.http.request import HttpRequest

from rinzler.auth.base_auth_service import BaseAuthService

class MyAuthenticationService(BaseAuthService):
    def authenticate(self, request: HttpRequest, auth_route: str, params: dict) -> bool:
        """
        Implement your authentication logic here
        :param request: HttpRequest Django's request object
        :param auth_route: str route being requested
        :param params: dict url params, if present
        :return: bool if not True, the request will be promptly returned with status-code 403
        """
        # Non-authenticated route
        if auth_route == 'GET_v1/hello/world/':
            return True

        # Authenticated routes
        if request.META.get("HTTP_AUTHORIZATION"):
            # after performing your authentication logic, you can append user data to the Rinzler object so it'll be available on the controller
            self.auth_data = {
                "user_id": 1,
            }
            return True

Then, you need to register your authentication service on the application's urls.py file.

# urls.py
from rinzler import boot, Rinzler

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


app: Rinzler = boot("MyApp")
app.set_auth_service(MyAuthenticationService())

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

Finally, you can access the user data on the controller by accessing the auth_data attribute on the Rinzler object.

# your_controller.py
from django.http.request import HttpRequest

from rinzler import Rinzler
from rinzler.core.response import Response


class Controller:
    # ...
    @staticmethod
    def hello_user(request: HttpRequest, app: Rinzler, **params: dict) -> Response:
        try:
            user = params['name']
            user_id = app.auth_data['user_id']
            response = {
                "status": True,
                "data": f"Hello {user}! Your user id is {user_id}.",
            }

            return Response(response, content_type="application/json")
        except BaseException as e:
            response = {
                "status": False,
                "mensagem": str(e),
            }
            return Response(response, content_type="application/json", status=500)

Sample requests

# Non-authenticated request
curl http://localhost:8000/hello/world/
{
  "status": true,
  "data": "Hello World!"
}

# Improperly authenticated request
curl http://localhost:8000/hello/bob/
# (empty response body with status-code 403)

# Properly authenticated request
curl http://localhost:8000/hello/bob/ -H "Authorization: XYZ"
{
  "status": true,
  "data": "Hello bob! Your user id is 1"
}

Download files

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

Source Distribution

rinzler-3.1.2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

rinzler-3.1.2-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file rinzler-3.1.2.tar.gz.

File metadata

  • Download URL: rinzler-3.1.2.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for rinzler-3.1.2.tar.gz
Algorithm Hash digest
SHA256 93fef68f30640f2cd69f6536be5309d31948cd606174915440b4a44762c751ac
MD5 c68269067f0bbe1b3bf29faadc269c5d
BLAKE2b-256 efcfc1596683ae003fa27bd846869fdc6ceeee556ecbe089c2d0ef4e11f7bd85

See more details on using hashes here.

Provenance

The following attestation bundles were made for rinzler-3.1.2.tar.gz:

Publisher: publish.yml on feliphebueno/Rinzler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rinzler-3.1.2-py3-none-any.whl.

File metadata

  • Download URL: rinzler-3.1.2-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for rinzler-3.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 58155d10f1384ccc801b86b503014015a42e31ae2f09e406f19bc1a41e3f970f
MD5 12d7ed7775e080b4b675a621a3ae4d89
BLAKE2b-256 cf52e331087869de173f24fd27574b5facbeb7bef36f189aa304f87e4576090c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rinzler-3.1.2-py3-none-any.whl:

Publisher: publish.yml on feliphebueno/Rinzler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

3.2.0

2 files

3.1.3

2 files

This release

3.1.2 This release

2 files

3.1.1

1 file

3.1.0

1 file

3.0.5

1 file

3.0.4

1 file

3.0.3

1 file

3.0.2

1 file

3.0.1

1 file

3.0.0

1 file

2.2.5

2 files

2.2.4

2 files

2.2.3

2 files

2.2.2

2 files

2.2.1

2 files

2.2.0

2 files

2.1.1

1 file

2.1.0

2 files

2.0.7

2 files

2.0.6

2 files

2.0.5

2 files

2.0.4

1 file

2.0.3

1 file

2.0.2

1 file

2.0.1

1 file

2.0.0

2 files

1.25.0

1 file

1.24.13

2 files

1.24.12

2 files

1.24.11

2 files

1.24.10

1 file

1.24.9

2 files

1.24.8

2 files

1.24.7

2 files

1.24.6

2 files

1.24.5

2 files

1.24.4

2 files

1.24.3

2 files

1.24.2

2 files

1.24.1

2 files

1.24.0

2 files

1.23.0

1 file

1.22.0

1 file

1.21.0

1 file

1.20.3

1 file

1.20.2

1 file

1.20.1

1 file

1.20.0

1 file

1.19.0

1 file

1.18.4

1 file

1.18.3

1 file

1.18.2

1 file

1.18.1

1 file

1.18.0

1 file

1.17.0

1 file

1.16.1

1 file

1.16.0

1 file

1.15.2

1 file

1.15.1

1 file

1.15.0

1 file

1.14.2

1 file

1.14.1

1 file

1.14.0

1 file

1.13.1

1 file

1.13.0

1 file

1.12.0

1 file

1.11.2

1 file

1.11.1

1 file

1.11.0

1 file

1.10.1

1 file

1.10.0

1 file

1.9.0

1 file

1.8.0

1 file

1.7.4

1 file

1.7.3

1 file

1.7.2

1 file

1.7.1

1 file

1.7.0

1 file

1.6.0

1 file

1.5.0

1 file

1.4.0

1 file

1.3.0

1 file

1.2.0

1 file

1.1.0

1 file

1.0.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page