Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kindly Introduce status code support for response #1376

Open
KapilDagur opened this issue Dec 30, 2024 · 3 comments
Open

Kindly Introduce status code support for response #1376

KapilDagur opened this issue Dec 30, 2024 · 3 comments

Comments

@KapilDagur
Copy link

Firstly Thanks to Django Ninja Teams for providing us Ninja.
I'm using Ninja from few months but I notice a issue which is not available in Ninja
i.e a Status Code support for Response so Kindly Introduce status module for such support.
Kindly Provide us this feature and improve our experience more.

Thanks & Regards
KAPIL DAGUR

@vitalik
Copy link
Owner

vitalik commented Dec 30, 2024

hi @KapilDagur not sure which status do you mean..

you can return http statuses like this:

@api.get('/some', response={200: Schema1, 201: Schema2})
def some(request):
      if something:
           return 200, data1
      else:
           return 201, data2

@KapilDagur
Copy link
Author

Thanks for replying @vitalik

You got my point I'm talking about http status code as 200

I want in ninja there should be a status Module like ninja.status where we have all status are mentioned like
Http_Ok for 200 status code
Http_Continue for 100 status code
As FastAPI have a status module for each status code

That's not any bug It's feature Improvement I suggested which would helpful for us not statics defining code 200 status.Http_Ok look more clear.

@vitalik
Copy link
Owner

vitalik commented Dec 30, 2024

htttp statuses and their descriptions are already in python standard library:

https://docs.python.org/3/library/http.html

>>> from http import HTTPStatus
>>> HTTPStatus.OK == 200
True
>>> HTTPStatus.OK.value
200
>>> HTTPStatus.OK.phrase
'OK'
>>> HTTPStatus.OK.description
'Request fulfilled, document follows'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants