Skip to content

Access to params of WPRequest #213

Description

@edygar

Is there anyway to retrieve all params from a built WPRequest?

What I'm looking for is an object like:

{
  "id": 2,
  "parent" : 1
}

Resulting from api.posts().id(1).revisions(2). And an object like:

{
  "id": 2
}

Resulting from api.posts().id(2). But the closer I've got was

function getIndexes(request) {
  /* eslint-disable no-param-reassign */
  // Internal mutations inside reduce function
  const foundIndexers = _reduce(request._path, (indexers, fragment, piece) => {
    const id = _find(request._levels[piece], cmp => cmp.validate(fragment));
    if (!id) return indexers;
    const name = id.component.match(namedGroupRegex);

    if (name) {
      indexers[name[1]] = fragment;
    }

    return indexers;
  }, { ...request._params });

  return foundIndexers;
}

Since I've no access to routesTree, I can't walk and assign the right name to each given _path component.

Thank you

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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