Index: /trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
===================================================================
--- /trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php	(revision 39342)
+++ /trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php	(revision 39343)
@@ -1929,5 +1929,5 @@
 			'description' => __( 'The theme file to use to display the object.' ),
 			'type'        => 'string',
-			'enum'        => array_keys( wp_get_theme()->get_page_templates( null, $this->post_type ) ),
+			'enum'        => array_merge( array_keys( wp_get_theme()->get_page_templates( null, $this->post_type ) ), array( '' ) ),
 			'context'     => array( 'view', 'edit' ),
 		);
Index: /trunk/tests/phpunit/includes/spy-rest-server.php
===================================================================
--- /trunk/tests/phpunit/includes/spy-rest-server.php	(revision 39342)
+++ /trunk/tests/phpunit/includes/spy-rest-server.php	(revision 39343)
@@ -6,4 +6,5 @@
 	public $sent_body = '';
 	public $last_request = null;
+	public $override_by_default = false;
 
 	/**
@@ -42,4 +43,18 @@
 	}
 
+	/**
+	 * Override the register_route method so we can re-register routes internally if needed.
+	 *
+	 * @param string $namespace  Namespace.
+	 * @param string $route      The REST route.
+	 * @param array  $route_args Route arguments.
+	 * @param bool   $override   Optional. Whether the route should be overridden if it already exists.
+	 *                           Default false. Also set $GLOBALS['wp_rest_server']->override_by_default = true
+	 *                           to set overrides when you don't have access to the caller context.
+	 */
+	public function register_route( $namespace, $route, $route_args, $override = false ) {
+		parent::register_route( $namespace, $route, $route_args, $override || $this->override_by_default );
+	}
+
 	public function serve_request( $path = null ) {
 
Index: /trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php
===================================================================
--- /trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php	(revision 39342)
+++ /trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php	(revision 39343)
@@ -28,4 +28,9 @@
 		$this->has_setup_template = false;
 		add_filter( 'theme_page_templates', array( $this, 'filter_theme_page_templates' ) );
+		// reregister the route as we now have a template available.
+		$GLOBALS['wp_rest_server']->override_by_default = true;
+		$controller = new WP_REST_Posts_Controller( 'page' );
+		$controller->register_routes();
+		$GLOBALS['wp_rest_server']->override_by_default = false;
 	}
 
Index: /trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
===================================================================
--- /trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php	(revision 39342)
+++ /trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php	(revision 39343)
@@ -1033,4 +1033,10 @@
 		add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) );
 
+		// reregister the route as we now have a template available.
+		$GLOBALS['wp_rest_server']->override_by_default = true;
+		$controller = new WP_REST_Posts_Controller( 'post' );
+		$controller->register_routes();
+		$GLOBALS['wp_rest_server']->override_by_default = false;
+
 		$request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
 		$params = $this->set_post_data( array(
@@ -1058,4 +1064,22 @@
 		$params = $this->set_post_data( array(
 			'template' => 'post-my-test-template.php',
+		) );
+		$request->set_body_params( $params );
+		$response = $this->server->dispatch( $request );
+
+		$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
+	}
+
+	/**
+	 * @ticket 38877
+	 */
+	public function test_create_item_with_template_none() {
+		wp_set_current_user( self::$editor_id );
+		add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) );
+		update_post_meta( self::$post_id, '_wp_page_template', 'post-my-test-template.php' );
+
+		$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
+		$params = $this->set_post_data( array(
+			'template' => '',
 		) );
 		$request->set_body_params( $params );
@@ -2055,4 +2079,60 @@
 		$this->assertErrorResponse( 'rest_cannot_assign_term', $response, 403 );
 	}
+
+	/**
+	 * @ticket 38698
+	 */
+	public function test_update_item_with_template() {
+		wp_set_current_user( self::$editor_id );
+		add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) );
+
+		// reregister the route as we now have a template available.
+		$GLOBALS['wp_rest_server']->override_by_default = true;
+		$controller = new WP_REST_Posts_Controller( 'post' );
+		$controller->register_routes();
+		$GLOBALS['wp_rest_server']->override_by_default = false;
+
+		$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
+		$params = $this->set_post_data( array(
+			'template' => 'post-my-test-template.php',
+		) );
+		$request->set_body_params( $params );
+		$response = $this->server->dispatch( $request );
+
+		$data = $response->get_data();
+		$post_template = get_page_template_slug( get_post( $data['id'] ) );
+
+		$this->assertEquals( 'post-my-test-template.php', $data['template'] );
+		$this->assertEquals( 'post-my-test-template.php', $post_template );
+	}
+
+	/**
+	 * @ticket 38877
+	 */
+	public function test_update_item_with_template_none() {
+		wp_set_current_user( self::$editor_id );
+		add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) );
+		update_post_meta( self::$post_id, '_wp_page_template', 'post-my-test-template.php' );
+
+		// reregister the route as we now have a template available.
+		$GLOBALS['wp_rest_server']->override_by_default = true;
+		$controller = new WP_REST_Posts_Controller( 'post' );
+		$controller->register_routes();
+		$GLOBALS['wp_rest_server']->override_by_default = false;
+
+		$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
+		$params = $this->set_post_data( array(
+			'template' => '',
+		) );
+		$request->set_body_params( $params );
+		$response = $this->server->dispatch( $request );
+
+		$data = $response->get_data();
+		$post_template = get_page_template_slug( get_post( $data['id'] ) );
+
+		$this->assertEquals( '', $data['template'] );
+		$this->assertEquals( '', $post_template );
+	}
+
 
 	public function verify_post_roundtrip( $input = array(), $expected_output = array() ) {
