WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#35822 closed defect (bug) (maybelater)

Add support for PATCH method to REST API infrastructure

Reported by: westonruter Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: REST API Keywords:
Focuses: Cc:

Description

The REST API infrastructure in Core presently does not support a JSON format for the body of PATCH requests. Supporting PATCH requests is a dependency for implementing Customizer transactions (#30937), where there will be a customize_transaction post type which contains a JSON blog of the dirty settings representing the Customizer state. Each change to a setting should result in a PATCH request to push the newly-dirty setting value into the dirty settings already in the customize_transaction post, as opposed to having to re-post the entire array of dirty settings with each request.

I understand that PATCH requests in the wild today commonly just include the sparse values that should be applied to the existing resource, but that the proper way to implement PATCH is to require that an explicit diff data format be used in the request body, such as a list of add, change, remove operations with a JSON path/pointer to apply to a resource (RFC 6902). Should JSON Patch (application/json-patch+json) be required for PATCH requests or should an informal sparse JSON object (application/json) be acceptable?

Change History (2)

#1 @rmccue
4 years ago

  • Keywords close added

IMO, we should close this as maybelater. The API can already handle PATCH requests, you just need to handle the patch format yourself in the endpoints. I think we should work out how we want JSON Patch operations to work first before we roll it into the infrastructure; the customiser provides a good place to do that and experiment.

Right now, something like this should already work:

register_rest_route( 'customizer/v1', '/test', array(
	'methods' => 'PATCH',
	'callback' => function ( WP_REST_Request $request ) {
		$body = $request->get_body();

		// Parse JSON Patch format into instructions
		$data = Some_JSON_Patch_Parser::parse( $body );

		// Do something with the instructions
	}
);

#2 @westonruter
4 years ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

????

(That was supposed to be an emoji thumbs up.)

Last edited 4 years ago by westonruter (previous) (diff)
Note: See TracTickets for help on using tickets.