Add URL Details endpoint to REST API to allow retrieval of info about a remote URL#18042
Add URL Details endpoint to REST API to allow retrieval of info about a remote URL#18042
Conversation
There was a problem hiding this comment.
@obenland Thanks for the changes! Really appreciate you taking this on and making it much better.
Left some small comments. Interested in what you think.
We need to wrangle some more feedback from the REST API group in Core.
We also need a rebase to make the playground pass (it's happened on all PRs recently).
Lastly, what do you think about this comment on the Issue?
2722e34 to
4c330d2
Compare
|
@kadamwhite We'd really appreciate your expertise and input on this if at all possible. |
|
@obenland Shall we try and move this forward in our next 20% time? What should we do to prepare for that so we can make progress at that time? |
|
Sure. I think double-checking #18042 (comment) would be the next step |
|
4c330d2 to
a5d9c25
Compare
|
Waiting on further feedback here. The outstanding issue blocking this from merging is the concern about exposing data about websites behind a firewall. Oh...and it looks like we have some PHPUnit test warnings @obenland. |
|
From what I could test, this doesn't expose data local data. Although I don't have a network behind a firewall etc, so I can't really comment about that. I tested this out and it worked fine. It did seem a bit odd the response wasn't actually JSON, just a string of the site's title. (I suppose returning JSON leaves the door open to returning other metadata about the site.) I wasn't aware of anywhere else in the REST API that just does that, but it's not the end of the world. |
Filter on both cached and uncached response.
|
Merged 🎉 I will raise followups to add extra functionality. Thanks to everyone for your help in getting this over the line (particularly @TimothyBJacobs and @swissspidy). |
|
Congrats @getdave! Nice work |
|
@TimothyBJacobs At some point if this endpoint is accepted would I need to follow up with this in WordPess Core? |
|
Whenever the JS feature that uses this feature is slated to be included in Core, we'll create a Core ticket for merging the URL details endpoint. I can take care of merging it into Core. |
That's great thanks. Any chance I could get involved there? Only Ive not committed to WP Core and this seems like a good opportunity. |
Yeah, you can absolutely take the lead on that! |
|
Here is a follow up #28791 |
Closes #18047.
Adds a new REST API endpoint to grab details from a external URL. So now if I want to get the contents of the
titletag onhttps://wordpress.orgI can send a request to this API endpoint and it will return the value in the response for use in the Gutenberg UI.Why might this be useful? See #19387.
As part of #17846 we need to display the contents of theThis has now long since shipped. Nonetheless, it might be a nice enhancement to be able to show details about the remote URL that has been selected.<title>tag from the url the user has typed into the input field.This PR addresses this by adding a new experimental custom Gutenberg REST API endpoint. This endpoint:
parses the response in awe should investigate this in future (see here)DOMDocumenttitletag contents.To prevent abuse, the endpoint is authenticated and requires the user to have the
edit_postscapability to be able to make a request.How has this been tested?
Automated Testing Instructions
npm run test-phpshould run the unit tests which reside inphpunit/class-wp-rest-url-details-controller-test.php.Manual Testing Instructions
http://localhost:8889/wp-admin/and login.Option 1
consoleenter:You'll see the response returned there.
Option 2
consoleenterwpApiSettings.nonce. You should see a valid nonce returned as a string.http://localhost:8889/wp-json/__experimental/url-details/?url=https://wordpress.org&_wpnonce=%YOUR_NONCE_HERE%- be sure to replace the nonce value with that copied from the previous step.wordpress.org(ie:"Blog Tool, Publishing Platform, and CMS \u2014 WordPress.org").Types of changes
New feature (non-breaking change which adds functionality).
Checklist: