Skip to content

Access route parameters within API function #1906

@oscartbeaumont

Description

@oscartbeaumont

It would be really useful if when defining a route with parameters that you can access the parameter from within the API function.

For example for a route defined at /_api/api/thing/[...slug].ts, it would be great to be able to easily (and maybe even with typesafety) access the value of the slug or for /_api/thing/:a/:b to be able to acess the a and b values.

It's possible this exists already and I am just missing it but I couldn't find any examples in the repo or docs when I searched.

Currently i've been manually passing the URL from the request which works but is not great for long term maintaince. Eg. it will break if I move the file around because it hardcodes the path.

Thanks!

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