API Documentation

This section provides the API documentation for BTHLabs JSONRPC - Core.

Auth checks

bthlabs_jsonrpc_django.has_perms(perms: list[str]) Callable

Checks if the request user has the specified permissions.

bthlabs_jsonrpc_django.is_authenticated(request: django.http.request.HttpRequest) bool

Checks if the request user is authenticated and active.

bthlabs_jsonrpc_django.is_staff(request: django.http.request.HttpRequest) bool

Checks if the request user is a staff user.

Views

class bthlabs_jsonrpc_django.JSONRPCView(**kwargs)

The JSONRPC View. This is the main JSONRPC entry point. Use it to register your JSONRPC endpoints.

Example:

from bthlabs_jsonrpc_django import JSONRPCView, is_authenticated

urlpatterns = [
    path(
        'rpc/private',
        JSONRPCView.as_view(
            auth_checks=[is_authenticated],
            namespace='admin',
        ),
    )
    path('rpc', JSONRPCView.as_view()),
]
classmethod as_view(**initkwargs)

Main entry point for a request-response process.

auth_checks: list[Callable] = []

List of auth check functions.

can_call(request: django.http.request.HttpRequest, method: str, args: list, kwargs: dict) bool

Hook for subclasses to perform additional per-call permissions checks etc. The default implementation returns True.

namespace: Optional[str] = None

Namespace of this endpoint.