API router does not respect WAGTAIL_APPEND_SLASH setting
See original GitHub issueIssue Summary
The API router will append slashes whether the WAGTAIL_APPEND_SLASH
is set to True
or False
. The behaviour is hardcoded in wagtail.api.v2.router.py
.
Changing the behaviour in the router might qualify as a breaking change, if the slash is just removed in case WAGTAIL_APPEND_SLASH
is set to False
. Right now clients are redirected from endpoint_without_slash to endpoint_with_slash with WAGTAIL_APPEND_SLASH
, but that won’t happen automatically the other way around.
DRF has the trailing_slash
argument for its router implementations so this might be a compromise to make the behaviour configurable while maintaining backwards compatibility until a breaking change is possible in the next (major?) version.
I’ll gladly submit a PR for a fix once we settled for a solution.
Thank you for your time!
Steps to Reproduce
- Follow the instructions in the documentation to setup the API
- Set
WAGTAIL_APPEND_SLASH
toFalse
in settings - Start the dev server
- Goto
/api/v2/pages
(which is immediately redirected to/api/v2/pages/
.
- I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes
Technical details
- Python version: 3.8.2
- Django version: 3.0.5
- Wagtail version: 2.8.1
- Browser version: Chromium 81
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top GitHub Comments
Thanks @kmohrf and @shipskin!
Unless there is a good reason for it, I’m against us making this change.
I don’t think this is a bug,
WAGTAIL_APPEND_SLASH
is only supposed to apply to page URLs by design. We support this because these URLs are what appear in a users browser and may be hand typed and this is not the case for the API.Supporting this would have a couple of disadvantages:
This was separately proposed and rejected in #7421 - sorry for not catching this earlier.