-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add api call to send data to server. Introduce data state var.
- Loading branch information
Showing
7 changed files
with
61 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const BACKEND_URL = "https://syar2tbuna.execute-api.us-east-1.amazonaws.com/" | ||
const DATA_ENDPOINT = "dev/data" | ||
|
||
function getData() { | ||
return fetch(`${BACKEND_URL}${DATA_ENDPOINT}`) | ||
.then(response => { | ||
if (response.ok) { | ||
return response.json() | ||
} throw new Error(response.statusText) | ||
}) | ||
.catch(error => { throw new Error(error.message) }); | ||
} | ||
|
||
function storeData(data) { | ||
return fetch(`${BACKEND_URL}${DATA_ENDPOINT}`, | ||
{ | ||
method: 'POST', | ||
body: JSON.stringify(data), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Credentials": true | ||
} | ||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
return response.json() | ||
} throw new Error(response.statusText) | ||
}) | ||
.catch(error => { throw new Error(error.message) }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.