-
Notifications
You must be signed in to change notification settings - Fork 65
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
Is there a way to have response headers passed? #13
Comments
When the request is triggered the response is formatted to return an array for you from the body of the Wordpress response. There is no way to get header data through the client instance. |
Thanks for clarifying this. In my opinion there should be a straight-forward way to implement pagination to make this library useful for more than just some minor use cases. |
This library is open source. Feel free to submit a PR if you'd like endpoints to store response headers and provide a way to retrieve them. Since we're using an HTTP library that adheres to https://www.php-fig.org/psr/psr-7/ we certainly have access to response headers. We use them here: https://github.com/varsitynewsnetwork/wordpress-rest-api-client/blob/master/src/Endpoint/AbstractWpEndpoint.php#L46-L49 |
@boboudreau what do you think about returning the response object for the developer implementing this library to decide whether to get the header or not, format the body json, etc? It seems to me that it can make it difficult to implement it to have to fetch the content and format it. Something the library does now. Maybe we can bring the return into an array with the 'headers' and 'content' keys? |
I like the idea, but it would inherently break the current usage/API, which makes me concerned about backwards compatibility. We could add another method like |
+1 for getResponse / getWithHeaders to use WP header fields: https://developer.wordpress.org/rest-api/using-the-rest-api/pagination/
|
Thank you for this helpful library, the only one for accessing the WP REST API with PHP – as far as I can see!
Now, my goal is to load every available post from the REST API to display them in a frontend.
As of the current WordPress version, we can only get 100 posts per request from the API.
Fortunately, there is a header
X-WP-TotalPages
, where I can see how many requests I would need to fire to get all available posts. (see https://wordpress.stackexchange.com/questions/217490/get-post-count-in-wp-rest-api-v2-and-get-all-categories/250589#250589).However, I don't see a way to get this header from the $client instance. Is there a way that I don't see?
Right now I do requests, until there are no posts in the response anymore. This leads to one request that I could save.
The text was updated successfully, but these errors were encountered: