admin管理员组文章数量:1422704
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?
本文标签: pluginsCustom REST API POST Endpoint Not Working404 error
版权声明:本文标题:plugins - Custom REST API POST Endpoint Not Working, 404 Error 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744729284a2621949.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论