Engineering-Best-Practices icon indicating copy to clipboard operation
Engineering-Best-Practices copied to clipboard

Update AJAX Endpoints section to recommend REST API endpoints

Open petenelson opened this issue 7 years ago • 4 comments

Now that core has both the built-in REST API endpoints as well as the ability to create custom endpoints, we should update the best practices to recommend custom endpoints instead of custom rewrite rules and template_redirect hooks.

https://10up.github.io/Engineering-Best-Practices/php/#ajax-endpoints

petenelson avatar Aug 16 '17 18:08 petenelson

Definitely agree. Would love to see a PR.

tlovett1 avatar Sep 26 '17 02:09 tlovett1

Propose splitting that section into two parts: Ajax endpoints (containing references to rest API) and scenarios where it's a non ajax endpoint (e.g. something that returns templates / dom partials ) and contains the current recommendations with rewrite_rules + template_redirect.

ivankruchkoff avatar Oct 13 '17 17:10 ivankruchkoff

With the rest_pre_serve_request filter, it's easy to return non-JSON responses from an endpoint, so I'd still lean towards not using rewrite rules and template redirects and instead still take full advantage of the sanitization, validation, permissions, etc from the REST API.

petenelson avatar Oct 13 '17 17:10 petenelson

@petenelson @ivankruchkoff Any updates on this?

timwright12 avatar Jun 11 '18 15:06 timwright12