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.2.0.tar.gz (25.0 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.2.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rinzler-3.2.0.tar.gz
Algorithm Hash digest
SHA256 b600de72dd39f537c37c8005627ddd50d7df2f9f2de529d2835ce0acbaefa242
MD5 0f69c19cd5e21bcaa3510a80adac27d4
BLAKE2b-256 95d35cd098d9f644ae01d395be86eaf9e699f60745ec146cf4912b77e2c80959

See more details on using hashes here.

Provenance

The following attestation bundles were made for rinzler-3.2.0.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: rinzler-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 945242072fd502eb458fe31d860c1a7c99221e7fb04519746cab0b1295c1d5f2
MD5 25d1357456fd40590a651d97134d5b7c
BLAKE2b-256 4b2e150bfbe300623ca9f950d20708e09305406a6c16d3173a94c9ae3b26b3b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for rinzler-3.2.0-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

This release

3.2.0 This release

2 files

3.1.3

2 files

3.1.2

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