From e804009ec5cc7bb804c229915ce1c8ebedaa88c7 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 5 Jun 2020 10:17:16 -0700 Subject: [PATCH 1/1] Add a new fetch_put_json This is very similar to fetch_post_json but with a different request method. In fact, we share the implementation with a new fetch_method_json that accepts which method to use. --- tictactoe/tictactoe.jsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tictactoe/tictactoe.jsx b/tictactoe/tictactoe.jsx index 5bb84f1..71690b9 100644 --- a/tictactoe/tictactoe.jsx +++ b/tictactoe/tictactoe.jsx @@ -143,9 +143,9 @@ class Board extends React.Component { } } -function fetch_post_json(api = '', data = {}) { +function fetch_method_json(method, api = '', data = {}) { const response = fetch(api, { - method: 'POST', + method: method, headers: { 'Content-Type': 'application/json' }, @@ -154,6 +154,14 @@ function fetch_post_json(api = '', data = {}) { return response; } +function fetch_post_json(api = '', data = {}) { + return fetch_method_json('POST', api, data); +} + +async function fetch_put_json(api = '', data = {}) { + return fetch_method_json('PUT', api, data); +} + class Game extends React.Component { constructor(props) { super(props); -- 2.43.0