Django-ninja
Shinobi is part of application kit focused on facilitating the use of Django Ninja with woosmap services.
Warning
django-ninja pre v1 is not supported anymore.
It adds a WoosmapAPI class on top of the NinjaAPI class, which adds default responses and schemes to the generated OpenAPI
docs and also has classes to be used with Django-Ninjas Authentication system.
Tip
Async views are supported in application-kit v2.3.0.
from application_kit.shinobi.api import WoosmapApi
from application_kit.shinobi.authentication import PublicKeyAuth, PrivateKeyAuth, PrivateKeyHeaderAuth
from application_kit.shinobi.decorators import terminate, chain
from application_kit.authenticator.decorators import authenticate_key
from application_kit.metrics.decorators import count_request
from ninja import Router, Schema
from typing import List
from django.http import HttpRequest
sample = WoosmapApi(description="Sample Test Application.")
api = Router(tags=["api"])
sample.add_router("", api)
class SearchResponse(Schema):
results: List[str]
@api.get(
"/search",
response={200: SearchResponse},
auth=[
PublicKeyAuth(),
PrivateKeyAuth(),
PrivateKeyHeaderAuth(),
],
)
@chain(authenticate_key(), count_request("TEST", "test"))
@terminate()
def search(request: HttpRequest) -> SearchResponse:
return SearchResponse(results=["result 1", "result 2", "result 3"])
@api.get(
"/search-async",
response={200: SearchResponse},
auth=[
PublicKeyAuth(),
PrivateKeyAuth(),
PrivateKeyHeaderAuth(),
],
)
@chain(authenticate_key(), count_request("TEST", "test"))
@terminate()
async def search(request: HttpRequest) -> SearchResponse:
"""Async views are supported as well."""
return SearchResponse(results=["result 1", "result 2", "result 3"])