• Resolved vishal.pa

    (@vishalpa)


    I am using custom endpoint and i have also JWT token authorization and it uses post method :

    https://localhost/mvc/wp-json/cargosite/v1/car-list-by-model

    Here above API is using POST method and also using JWT token

    How ever for a check i disabled jwt token but still it does not work. Here is my code which i place in functions.php

    function wprc_add_acf_posts_endpoint( $allowed_endpoints ) {
    if ( ! isset( $allowed_endpoints[ 'cargosite/v1' ] ) || ! in_array( 'car-list-by-model', $allowed_endpoints[ 'cargosite/v1' ] ) ) {
    $allowed_endpoints[ 'cargosite/v1' ][] = 'car-list-by-model';
    }
    return $allowed_endpoints;
    }
    add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_acf_posts_endpoint', 10, 1);

    • This topic was modified 1 year, 6 months ago by vishal.pa.
Viewing 1 replies (of 1 total)
  • Plugin Author Richard Korthuis

    (@rockfire)

    Hi @vishalpa

    Thank you for using our plugin!

    The reason our plugin isn’t caching your endpoint is because of the POST method. By default our plugin only caches GET methods, because POST methods are usually used to create new entries and that isn’t something you want cached. However if you still want your POST to be cached you can use our wp_rest_cache/allowed_request_methods filter like this:

    /**
     * Allow POST requests to be cached.
     *
     * @param array $allowed_request_methods An array of request methods that are allowed to be cached.
     *
     * @return array
     */
    function wprc_filter_allowed_request_methods( $allowed_request_methods ) {
    	$allowed_request_methods[] = 'POST';
    
    	return $allowed_request_methods;
    }
    
    add_filter( 'wp_rest_cache/allowed_request_methods', 'wprc_filter_allowed_request_methods', 10, 1 );
Viewing 1 replies (of 1 total)
  • The topic ‘custom endpoint’ is closed to new replies.