Make WordPress Core

Opened 4 months ago

Last modified 8 weeks ago

#41549 assigned enhancement

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

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


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 8 weeks ago.

Download all attachments as: .zip

Change History (5)

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

8 weeks ago

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

8 weeks ago

#3 @adamsilverstein
8 weeks ago

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

#4 @adamsilverstein
8 weeks 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.

Note: See TracTickets for help on using tickets.