-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug.html
95 lines (74 loc) · 1.75 KB
/
debug.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<html>
<head>
<title>API Debugger</title>
<style>
.center {
text-align: center;
margin-left: auto;
margin-right: auto;
margin-top: 100px;
}
textarea {
width: 600px;
height: 450px;
font-size: 18px;
}
input {
height: 30px;
width: 1200px;
font-size: 15px;
}
button {
font-size: 20px;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="center">
<h1>API-Debugger</h1>
<div>
<input id="url" placeholder="/api" />
<br><br>
</div>
<div>
<textarea id="body" placeholder="Body"></textarea>
<textarea id="response" placeholder="Response"></textarea>
</div>
<div>
<button onclick="submit('GET')">GET</button>
<button onclick="submit('POST')">POST</button>
<button onclick="submit('PUT')">PUT</button>
<button onclick="submit('DELETE')">DELETE</button>
</div>
<div>
<button onclick="toJSON()">Beauty-JSON</button>
</div>
</div>
</body>
</html>
<script>
function submit(method)
{
var http = new XMLHttpRequest();
http.open(method, document.getElementById('url').value, true);
http.onreadystatechange = function() {
if(http.readyState == 4)
{
if(http.status == 200 | http.status == 201 | http.status == 202)
{
document.getElementById('response').value = http.responseText;
}
else
{
document.getElementById('response').value = "Error: " + http.status;
}
}
}
http.send(document.getElementById('body').value);
}
function toJSON()
{
document.getElementById('response').value = JSON.stringify(JSON.parse(document.getElementById('response').value), null, '\t');
}
</script>