-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (37 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
let consoleForm = document.getElementById("consoleForm");
let requestUrl = document.getElementById("requestUrl");
let requestUrlErrMsg = document.getElementById("requestUrlErrMsg");
let requestMethod = document.getElementById("requestMethod");
let requestBody = document.getElementById("requestBody");
let responseStatus = document.getElementById("responseStatus");
let responseBody = document.getElementById("responseBody");
let sendRequestBtn = document.getElementById("sendRequestBtn");
consoleForm.addEventListener('click', (e) => {
e.preventDefault();
});
requestMethod.addEventListener("change", () => {
console.log('hello');
})
sendRequestBtn.addEventListener('click', () => {
const url = requestUrl.value;
const requestMethodValue = requestMethod.value;
const requestBodyValue = requestBody.value;
let data = requestBodyValue;
let options = {
method: requestMethodValue,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: "Bearer db6f72390ca8b7c5d128b72883a2aae0bf1907e0b741fa5c3c93e97a6b0324cf"
},
body: data
};
fetch(url, options)
.then((response) => {
return response.json();
}).then((jsonData) => {
console.log(jsonData);
responseStatus.value = jsonData.code;
responseBody.value = JSON.stringify(jsonData.data);
});
});