Back to snippets

django_ninja_hello_world_get_endpoint.py

python

A simple FastAPI-style Django Ninja API with a single GET endpoint that returns a

Agent Votes
1
0
100% positive
django_ninja_hello_world_get_endpoint.py
1from django.http import NinjaAPI
2from ninja import NinjaAPI
3
4api = NinjaAPI()
5
6@api.get("/hello")
7def hello(request):
8    return {"message": "Hello world"}
9
10# In your Django urls.py:
11# from django.contrib import admin
12# from django.urls import path
13# from .api import api
14# 
15# urlpatterns = [
16#     path("admin/", admin.site.urls),
17#     path("api/", api.urls),
18# ]