hug
hug copied to clipboard
prefixes and suffixes add extra endpoints
A file like
import hug
@hug.get(suffixes = ['yo'])
def hello(request):
return 'hello'
@hug.get(prefixes = ['/my'])
def hi(request):
return 'hello'
will export
/hello
/helloyo
/hi
/my/hi
expected behaviour: following the description only the routes with suffixes and prefixes are exposed, in this example
/helloyo
/my/hi
typo in documentation
- `prefixes`: A list of or a single suffix to add to the end of all URLs using this router.
@timothycrosley The problem still persists with the current release:
> hug --version
hug 2.5.4
> hug -f hug-issue451.py
> http://localhost:8000 | grep '"/.*'
"/hello": {
"/helloyo": {
"/hi": {
"/my/hi": {
Reading ./tests/test_decorators.py
this seems to be intended behaviour, so the documentation should be changed to say that prefixes
and suffices
will add additional endpoints for each URLs using this routers. (As opposed to all URLs
which can be missread that afterwards all URLs will have the prefixes or suffixes.)
Hi @bernhardreiter,
Sorry I closed this incorrectly! I started going through the process of cleaning up issues, and misinterpreted the pull request attached to this as a sign that it had been resolved, I'm reopening it with both a question and enhancement tag (to signify better documentation is needed, and that there is also probably room here for an enhancement (support both behaviors?)
Thanks!
~Timothy
HI @timothycrosley, thanks for reopening the issue and the explanation.
My problem is that I do not understand the use cases for the feature. I wanted to use prefixes
to be able to move a bunch of endpoints somewhere. (If I remember correctly.) However this does not work with the current implementation as it keeps the old endpoint and only adds additional ones. So the real question is: what is the intended use case?
I've prepared a HOPE to address this issue thoroughly in the next major release of Hug: https://github.com/hugapi/HOPE/pull/13/files?short_path=320a69c#diff-320a69caca9872fec71ba5a452b02232. The original logic behind the parameters was for specific features such as hug_explainable, that want to add extensions to expose optional behavior - but never remove or modify the original links. I hope with the new behavior as lined out in the HOPE both will be easily doable.
Thanks again for raising this issue, and I'd appreciate any further feedback that you have.
Thanks!
~Timothy