Skip to content

incorrect routing in versioned API #654

@janpom

Description

@janpom

I have encountered a minor problem in request routing with versioned API.

# routing_bug.py

import hug

api = hug.http(versions=1)
api_get = api.accept('GET')


@api_get.urls("/{key}")
def get(key: hug.types.text):
    db = {'foo': 'bar'}
    if key in db:
        return {'value': db[key]}
    else:
        return {'error': '%r not found' % key}
$ hug -f routing_bug.py
$ curl -XGET http://127.0.0.1:8000/v1/foo
{"value":"bar"}
$ curl -XGET http://127.0.0.1:8000/v1/foo2
{"error":"'foo2' not found"}
$ curl -XGET http://127.0.0.1:8000/v1
{"error":"'v1' not found"}

The last is unexpected. The query gets routed to the /{key} endpoint with key="v1". However, v1 is the version, not the key. Expected behaviour is either to route to /{key} with key="" or report that the endpoint does not exist.

$ python --version
Python 3.5.4
$ pip freeze | grep hug
hug==2.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions