Make WordPress Core

Opened 8 years ago

Closed 5 years ago

Last modified 5 years ago

#41549 closed enhancement (wontfix)

REST API: Use `wp.apiRequest` helper in `wp.api` Backbone client

Reported by: jnylen0's profile jnylen0 Owned by: adamsilverstein's profile adamsilverstein
Milestone: Priority: normal
Severity: normal Version:
Component: REST API Keywords: needs-patch needs-unit-tests dev-feedback
Focuses: javascript, administration, rest-api Cc:

Description

Follow-up to #40919. The wp-api.js Backbone client should use wp.apiRequest to do its API calls. This may be accomplished through overriding Backbone.ajax or through a change in the wp-api.js code.

This will allow client-side code to override or modify all WP REST API calls in a single, centralized place.

cc @adamsilverstein for your thoughts on the best way to achieve this.

Attachments (1)

41549.diff (2.1 KB) - added by adamsilverstein 7 years ago.

Download all attachments as: .zip

Change History (9)

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.


7 years ago

#3 @adamsilverstein
7 years ago

  • Owner set to adamsilverstein
  • Status changed from new to assigned

#4 @adamsilverstein
7 years ago

  • Keywords dev-feedback added
  • Milestone changed from 4.9 to Future Release

@jnylen0 - 41549.diff is a first pass at this.

  • Override Backbone.ajax with wp.apiRequest.transport - I looked at replacing first with wp.apiRequest, however I don't think we need the additional logic in buildAjaxOptions and this might break something.
  • Immediately restore Backbone.ajax after use
  • Adjust tests to override wp.apiRequest.transport for testing

Not sure I like this - my concern here is that Backbone authors are used to the idea of being able to override Backbone.ajax to use an alternate method, for example this native implementation. This would actually break that (for the client), requiring that they override wp.apiRequest.transport instead.

Punting for now for further consideration.

#5 @jnylen0
7 years ago

@adamsilverstein I think most of the value in this change is in having wp-api.js use buildAjaxOptions. I could have explained the reasoning better in the ticket, but here is a good example of how this could be helpful: #42807

I am not sure how to handle users overriding Backbone.ajax. It would be good to see an example of this in WordPress context, otherwise I think it is probably not very common.

#6 @adamsilverstein
5 years ago

@jnylen0 Is this change still needed? If not, let's close this out.

#7 @jnylen0
5 years ago

  • Resolution set to wontfix
  • Status changed from assigned to closed

Doesn't seem to be needed any more.

#8 @desrosj
5 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.