Skip to content

Any way to declare type of path parameters ? #3400

@buxx

Description

@buxx

Story

When declare a path with regex, parameters can't be delcared with a type.

Actual behaviour

All path parameters are string.

Steps to reproduce

from aiohttp import web


async def handle(request):
    name = request.match_info.get('id', 42)
    text = str(type(name))
    return web.Response(text=text)

app = web.Application()
app.add_routes([web.get('/', handle),
                web.get(r'/{id:\d+}', handle)])

web.run_app(app)
$ http :8080/42
HTTP/1.1 200 OK
Content-Length: 13
Content-Type: text/plain; charset=utf-8
Date: Tue, 20 Nov 2018 16:33:58 GMT
Server: Python/3.7 aiohttp/3.4.4

<class 'str'>

My question/issue

It exist a way to declare the type of path parameters ? I would like obtain an int in this example.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions