question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access to params of WPRequest

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kadamwhitecommented, Sep 7, 2016

@edygar This is awesome, I look forward to digging into it (and hopefully coming up with a solution that works for both of us) in the coming week.

0reactions
edygarcommented, Sep 2, 2016

Just so you know, I just published the very first version of the lib.

This current issue was poorly addressed here. getIndexes should grab any useful information for finding an entity, my wish as that I could extract the params with the right params name.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I access parameters from a POST (or other HTTP ...
I have a JS component that (to the best of my knowledge) is making an appropriate fetch request (POST) to a C# server...
Read more >
Get Query Strings and Parameters in Express.js - Stack Abuse
Your query parameters can be retrieved from the query object on the request object sent to your route. It is in the form...
Read more >
How to access query string parameters - Node.js
Another way to access query string parameters is parsing them using the querystring builtin Node.js module. This method, however, must be passed ...
Read more >
HTTP Requests - The PHP Framework For Web Artisans
Accessing The Request · App\Http\Controllers; · Illuminate\Http\Request; · UserController extends Controller · /** · @param Request $request · @param string $id · @ ......
Read more >
How to Access Query Parameters in Javascript - Rad Devon
We can use the window 's location object to get the parameter string. The parameter string is in the search property. const queryParamsString...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found