Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best approach to determine which entities are present in a REST API response #2

Open
luisherranz opened this issue Nov 12, 2020 · 2 comments

Comments

@luisherranz
Copy link
Contributor

Hey guys, I was taking a look at the code and I saw that the approach you use is different than what the Pantheon people is doing:

It looks like they are using the rest_prepare_xxx filters to add that entity to a global array. That works well with _embed=true because the rest_prepare_xxx filters of the embedded entities are also called.

My question is: why did you choose to extract the entities from the fields present in the response? Is there a benefit from doing so, or did you find that the Pantheon's approach has some edge cases that are not covered?

@richardkorthuis
Copy link
Collaborator

Hi,

To be honest, we never thought about doing it that way :P

When we initially developed the wp-rest-cache plugin it was for our internal projects. And in those projects we use Advanced Custom Fields together with the ACF to REST API plugin. Now in these ACF fields we use the Post Object field, this post object is also include in the REST response and doesn't use any of the rest_prepare_xxx filters. So since we wanted those entities to also be considered we needed a different approach.

However, I do like the rest_prepare_xxx approach especially since that method would still work correctly when using the _fields parameter. If you would do a request with ?_fields=id,title our approach breaks...
Now since internally we have been using / developing an ACF to REST API add-on for WP REST Cache, we could move the logic for those cases to the add-on and have the WP REST Cache plugin switch to the rest_prepare_xxx approach. So I am adding this to our list of future improvements.

@luisherranz
Copy link
Contributor Author

Nice, good to know 🙂

If you would do a request with ?\_fields=id,title our approach breaks...

That's true. I wonder if Pantheon's approach also has any edge cases where it doesn't work...

@stevector, @danielbachhuber what is your experience? Have you found any issue or edge case with your approach? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants