sanic-org / sanic-routing

Internal handler routing for Sanic beginning with v21.3.

Home Page:https://sanicframework.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API for adding patterns

ahopkins opened this issue · comments

Currently .patterns supports a fixed set of patterns using REGEX_TYPES.

This should be expanded so that custom patterns can be added at run time.

router.register_pattern("ipv4", ipaddress.ip_address, r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$")

Then, it should be usable:

@app.route("/foo/<ip:ipv4>")
async def handler(request, ip: IPv4Address):
    ....

Included in #30