RestAPI, limit fields in response + Cache strategies

Support MB REST API RestAPI, limit fields in response + Cache strategies

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #46425
    jw_blnjw_bln
    Participant

    May I ask how you deal with the above-mentioned two topics?

    Is there a possibility to reduce the data (fields) in a RestAPI response?
    Let's say, I have a post where I have a text-teaser-field and a post-WYSIWIG-field, but want the answer limited to ONLY send the text-teaser-field, Also I may want to avoid send all (unnecessary) the category information - so (maybe) I want to have only the fields of the meta_box part in the answer...

    Related to caching REST-API requests:
    What is the correct way in WP/MB to let the client only refresh the REST-API answer every single day or whatever timeframe is defined?

    #46449
    PeterPeter
    Moderator

    Hello,

    1. You can follow the documentation to hide a field from Rest API
    https://docs.metabox.io/extensions/mb-rest-api/#hiding-a-field

    2. MB Rest API doesn't support a feature to cache the rest request. You can use a third-party plugin to cache the request, for example
    https://wordpress.org/plugins/wp-rest-cache/
    https://wordpress.org/plugins/litespeed-cache/

    #46458
    jw_blnjw_bln
    Participant

    Thanks for your response.
    I guess I was not precise enough 😉
    Yes, I know I can use LiteSpeed caching or similar (server-side caching).
    What I was looking for was something like cache-control-headers (maybe WP_REST_Server::send_headers) for specific routes to enable client-side caching.
    I am still on the way, to find the best solution.

    But regarding fields of MB:
    It's not only about hiding fields.
    Most likely I am looking for something like
    - a route 1, where I can have the full field set
    - and route 2, where I can have only a subset
    What would be your recommended way (please with a simple example)...

    Also, is there any possibility to output ONLY MB_fields?
    I want to exclude any other fields from WP like category information, URL, etc...

    #46460
    PeterPeter
    Moderator

    Hello,

    Please notice that MB Rest API doesn't create a new route, it only adds the key "meta_box" to the WordPress endpoints (routes) and allows you to get/update the meta box fields. So I'm afraid that it doesn't meet your requirements.
    Following the documentation https://docs.metabox.io/extensions/mb-rest-api/

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.