Skip to content

Support for trailing route components after named component #385

Open
@seantjohnson-dev

Description

@seantjohnson-dev

Hey there,

I was just trying to create a custom route for my application and I noticed that the method 'registerRoute' only allows a named parameter to live at the end of the endpoint structure. For example, the following route works just fine.

WP.registerRoute('gf/v2', "/entries/(?P<id>\\d+)");

The above route will create a final url resembling something like https://youdomain.com/wp-json/gf/v2/entries/77

However, the following use of registerRoute does not work.

WP.registerRoute('gf/v2', "/entries/(?P<id>\\d+)/notifications");

The route above still produces the same final url structure as the first example I listed above.

I end up getting this https://youdomain.com/wp-json/gf/v2/entries/77 instead of https://youdomain.com/wp-json/gf/v2/entries/77/notifications.

This happens to be the structure of a few of the routes created by the gravity forms rest api plugin.

image

However, this endpoint structure happens to be quite common amongst many other rest api plugins as well.

I don't know how to get the trailing slug of the url to be added to the end of the path. Is this currently supported and I'm just missing something obvious or would this need to be a new feature? Any help would be much appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions