django-rest-framework
django-rest-framework copied to clipboard
[RFE] Default response to OPTIONS requests are incomplete
Checklist
- [X] I have verified that that issue exists against the
masterbranch of Django REST framework. - [X] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- [X] This is not a usage question. (Those should be directed to the discussion group instead.)
- [X] This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- [X] I have reduced the issue to the simplest possible case.
- [X] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.) ** Sort of: I have fixed the test cases that start failing in response to adding this improved functionality.
Steps to reproduce
Without overriding the default OPTIONS handler, make such a request when methods other than POST and PATCH are permitted for the authorized (if applicable) user -- most notably GET.
Expected behavior
The response should include all relevant HTTP methods as available "actions". If a client can make a GET request to the API, then an OPTIONS request should include that as a valid action. This would be consistent with W3C specification and implementation/documentation by others, e.g.:
- Mozilla - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
- Widely used Spring framework - https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-ann-requestmapping-head-options
Highly related is that "choices" can be used as filters on requests, so being able to query for them even on read-only resources is also vitally useful to creating well-designed client libraries of APIs. The current behavior of reporting that no requests are possible on objects that are in fact queryable unnecessarily forces externalization of source-of-truth data about choices onto clients and creates maintenance overhead to avoid desynchronization in the face of API updates.
https://github.com/encode/django-rest-framework/pull/7644
Actual behavior
Only POST and PATCH are reported as available actions, despite GET requests being accepted for the object.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I believe the rationale for this is still valid, and the pull request for this change is already prepared.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I believe the rationale for this is still valid, and the pull request for this change is already prepared.
This is a nice idea for many use cases, but in others the choice fields might contain many thousands of possible options.
I don't think we'd want this generally on for all sites.