[wp-trac] [WordPress Trac] #38922: Use REST API for ajax tag search

WordPress Trac noreply at wordpress.org
Mon Dec 5 08:13:45 UTC 2016


#38922: Use REST API for ajax tag search
--------------------------+------------------------------
 Reporter:  nacin         |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Taxonomy      |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  rest-api
--------------------------+------------------------------

Comment (by afercia):

 Worth noting the REST API response return by default ''all'' the fields,
 even the ones that in this case are not needed, while the traditional old
 AJAX way returns just the terms. Quickly testing on a VVV install,
 searching for `co`, here's a quick comparison:

 AJAX: 430B, 112ms
 {{{
 claycold
 Codex
 comments
 content
 shortcode
 }}}

 REST API: 3.6KB, 168ms
 {{{
 [
 {"id":76,"count":0,"description":"","link":"http:\/\/src.wordpress-
 develop.dev\/tag\/claycold\/","name":"claycold","slug":"claycold","taxonomy":"post_tag","meta":[],"_links":{"self":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/tags\/76"}],"collection":[{"href":"http:\/\/src.wordpress-
 develop.dev\/wp-json\/wp\/v2\/tags"}],"about":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/taxonomies\/post_tag"}],"wp:post_type":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/posts?tags=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},
 {"id":77,"count":4,"description":"","link":"http:\/\/src.wordpress-
 develop.dev\/tag\/codex\/","name":"Codex","slug":"codex","taxonomy":"post_tag","meta":[],"_links":{"self":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/tags\/77"}],"collection":[{"href":"http:\/\/src.wordpress-
 develop.dev\/wp-json\/wp\/v2\/tags"}],"about":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/taxonomies\/post_tag"}],"wp:post_type":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/posts?tags=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},
 {"id":78,"count":5,"description":"","link":"http:\/\/src.wordpress-
 develop.dev\/tag\/comments-2\/","name":"comments","slug":"comments-2","taxonomy":"post_tag","meta":[],"_links":{"self":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/tags\/78"}],"collection":[{"href":"http:\/\/src.wordpress-
 develop.dev\/wp-json\/wp\/v2\/tags"}],"about":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/taxonomies\/post_tag"}],"wp:post_type":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/posts?tags=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},
 {"id":79,"count":13,"description":"","link":"http:\/\/src.wordpress-
 develop.dev\/tag\/content-2\/","name":"content","slug":"content-2","taxonomy":"post_tag","meta":[],"_links":{"self":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/tags\/79"}],"collection":[{"href":"http:\/\/src.wordpress-
 develop.dev\/wp-json\/wp\/v2\/tags"}],"about":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/taxonomies\/post_tag"}],"wp:post_type":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/posts?tags=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},
 {"id":146,"count":6,"description":"","link":"http:\/\/src.wordpress-
 develop.dev\/tag\/shortcode\/","name":"shortcode","slug":"shortcode","taxonomy":"post_tag","meta":[],"_links":{"self":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/tags\/146"}],"collection":[{"href":"http:\/\/src.wordpress-
 develop.dev\/wp-json\/wp\/v2\/tags"}],"about":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/taxonomies\/post_tag"}],"wp:post_type":[{"href":"http:\/\/src
 .wordpress-develop.dev\/wp-
 json\/wp\/v2\/posts?tags=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
 ]
 }}}

 I'm really not an expert about the REST API, just wondering what is the
 advantage in using them ''in this specific case''.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38922#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list