From 06eec590899e6c8775d1a25454a6224b3d1f7bd9 Mon Sep 17 00:00:00 2001 From: Luke Herrington Date: Tue, 6 Jun 2017 10:33:10 -0700 Subject: [PATCH] Copy body data for PATCH when sending request. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: ## Motivation Solves the issue outlined in #218 When `PATCH`ing, the body of the request is not sent. ## Test Plan Inside of a `componentDidMount` or some event handler in your react-vr codebase, add the following code: ```js const payload = { data: { id: 'de0db600-9a0a-416d-b42b-a19d31aad039', attributes: { field_rotation: '-96', field_rotation_x: '10', }, }, }; fetch(`http://httpbin.org/patch`, { method: 'patch', body: JSON.stringify(payload), headers: { "Content-Type": "application/vnd.api+json" } }) .then(res => res.json()) .then(console.log) ``` In the console, you should see react-vr-body-pr-success Thank you for all of your hard work on this project. ❤️ 😄 Closes https://github.com/facebook/react-vr/pull/219 Reviewed By: amberroy Differential Revision: D5190034 Pulled By: amberroy fbshipit-source-id: 2200ede --- ReactVR/js/Modules/Networking.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ReactVR/js/Modules/Networking.js b/ReactVR/js/Modules/Networking.js index b3cb96a22..fc3ecd604 100755 --- a/ReactVR/js/Modules/Networking.js +++ b/ReactVR/js/Modules/Networking.js @@ -69,8 +69,8 @@ export default class Networking extends Module { headers: headers, }; - // copy over the body data for POST in the correct form - if (method === 'POST' && data) { + // copy over the body data for POST/PATCH in the correct form + if ((method === 'POST' || method === 'PATCH') && data) { if (data.string) { options.body = data.string; } else if (data.formData) {