Add SimplePathRouter by sevdog · Pull Request #6789 · encode/django-rest-framework (original) (raw)
I am playing around with this PR a bit, and in my case the major reason I am trying to move to path
over regular expressions is to get custom converter behaviors for the URL arguments. I have a function that transforms my model IDs as they come into and out of the API layer, and I have implemented this as a custom converter to do something like <encoded:pk>
instead of <int:pk>
to automatically decode the IDs before they reach any of my code.
I am able to make this work with the code in this PR by setting lookup_value_regex = "encoded"
on my views. However, since I am not defining a regex here, the usage feels a little unnatural. The same behavior would apply to standard converters, like uuid
.
This isn't a blocker, since it seems to be working just fine, but figured it was worth bringing up while it is still in PR. If there is an alternative way to approach these custom converters, let me know, and I will give that a try too.