Skip to content

Commit 184c255

Browse files
committed
feat: add request example from fetch
1 parent ac94bc4 commit 184c255

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

javascript/fetch.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,24 @@ const someObject = {
2929
sendRequest("POST", requestURL, someObject)
3030
.then(data => console.log(data))
3131
.catch(error => console.error(error))
32+
33+
34+
35+
async function sendRequestAsync(model, url) {
36+
const response = await fetch(url, {
37+
method: 'POST',
38+
headers: {
39+
'Content-Type': 'application/json'
40+
},
41+
body: JSON.stringify(model)
42+
});
43+
const data = await response.json();
44+
return data;
45+
}
46+
47+
async function fetchRequest() {
48+
const model = {
49+
prop: "value",
50+
}
51+
const result = await sendRequestAsync(model, url);
52+
}

javascript/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ const someObject = {
4444

4545
sendRequest("POST", requestURL, someObject)
4646
.then(data => console.log(data))
47-
.catch(error => console.error(error))
47+
.catch(error => console.error(error))

0 commit comments

Comments
 (0)