最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Custom REST API POST Endpoint Not Working, 404 Error

programmeradmin1浏览0评论

I'm writing a plugin, and I'm having some trouble with the custom endpoint that takes in data from the front-end of the app (Angular), and will pass it another function to filter some data. I have the GET request to the product database working just fine, but the POST just returns a 404 error. Solutions I've tried include making sure that pretty permalinks were set, switching themes, all to no avail. I have also checked the wp-json file, and it is showing up in there. The code for this endpoint:

function get_awesome_params(WP_REST_Request $request) {
  // question attributes from angular code
  $parameters = $request->get_params();
  return new WP_REST_Response($parameters, 200);
}

add_action('rest_api_init', function() {
  register_rest_route('awesome/v1', '/awesomeparams', array(
    'methods' => WP_REST_Server::CREATABLE,
    'callback' => 'get_awesome_params',
    'permission_callback' => function () {
      return true;
    }
  ));
});

EDIT: Error message on visiting page is:

{
  code: "rest_no_route",
  message: "No route was found matching the URL and request method",
  data: {
    status: 404
  }
}

EDIT: Is it because I don't have a custom content type set up for the $request argument?

发布评论

评论列表(0)

  1. 暂无评论