-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-tester.html
More file actions
198 lines (184 loc) · 6.97 KB
/
api-tester.html
File metadata and controls
198 lines (184 loc) · 6.97 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jump API Tester</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.container {
display: flex;
flex-direction: column;
gap: 20px;
}
.card {
border: 1px solid #ccc;
border-radius: 5px;
padding: 15px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.response {
background-color: #f5f5f5;
padding: 10px;
border-radius: 5px;
white-space: pre-wrap;
max-height: 300px;
overflow: auto;
}
button {
padding: 8px 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background-color: #45a049;
}
input, textarea {
width: 100%;
padding: 8px;
margin: 5px 0;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}
label {
font-weight: bold;
}
.success {
color: #4CAF50;
}
.error {
color: #f44336;
}
</style>
</head>
<body>
<h1>Jump API Tester</h1>
<div class="container">
<div class="card">
<h2>Health Check</h2>
<button id="healthCheck">Test Health Endpoint</button>
<h3>Response:</h3>
<div id="healthResponse" class="response"></div>
</div>
<div class="card">
<h2>Create Payload</h2>
<div>
<label for="content">Content:</label>
<textarea id="content" rows="4">Test payload content</textarea>
</div>
<div>
<label for="mimeType">MIME Type:</label>
<input type="text" id="mimeType" value="text/plain">
</div>
<button id="createPayload">Create Payload</button>
<h3>Response:</h3>
<div id="createResponse" class="response"></div>
</div>
<div class="card">
<h2>Get Payload</h2>
<div>
<label for="payloadId">Payload ID:</label>
<input type="text" id="payloadId">
</div>
<button id="getPayload">Get Payload</button>
<h3>Response:</h3>
<div id="getResponse" class="response"></div>
</div>
<div class="card">
<h2>Delete Payload</h2>
<div>
<label for="deletePayloadId">Payload ID:</label>
<input type="text" id="deletePayloadId">
</div>
<button id="deletePayload">Delete Payload</button>
<h3>Response:</h3>
<div id="deleteResponse" class="response"></div>
</div>
</div>
<script>
const API_BASE_URL = 'http://localhost:8080/api';
// Health Check
document.getElementById('healthCheck').addEventListener('click', async () => {
try {
const response = await fetch(`${API_BASE_URL}/health`);
const data = await response.json();
document.getElementById('healthResponse').textContent = JSON.stringify(data, null, 2);
} catch (error) {
document.getElementById('healthResponse').textContent = `Error: ${error.message}`;
}
});
// Create Payload
document.getElementById('createPayload').addEventListener('click', async () => {
try {
const content = document.getElementById('content').value;
const mimeType = document.getElementById('mimeType').value;
const response = await fetch(`${API_BASE_URL}/v1/payloads`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
content,
mime_type: mimeType
})
});
const data = await response.json();
document.getElementById('createResponse').textContent = JSON.stringify(data, null, 2);
// Auto-fill the payload ID for get and delete
if (data.hash_id) {
document.getElementById('payloadId').value = data.hash_id;
document.getElementById('deletePayloadId').value = data.hash_id;
}
} catch (error) {
document.getElementById('createResponse').textContent = `Error: ${error.message}`;
}
});
// Get Payload
document.getElementById('getPayload').addEventListener('click', async () => {
try {
const payloadId = document.getElementById('payloadId').value;
if (!payloadId) {
document.getElementById('getResponse').textContent = 'Error: Please enter a payload ID';
return;
}
const response = await fetch(`${API_BASE_URL}/v1/payloads/${payloadId}`);
const data = await response.json();
document.getElementById('getResponse').textContent = JSON.stringify(data, null, 2);
} catch (error) {
document.getElementById('getResponse').textContent = `Error: ${error.message}`;
}
});
// Delete Payload
document.getElementById('deletePayload').addEventListener('click', async () => {
try {
const payloadId = document.getElementById('deletePayloadId').value;
if (!payloadId) {
document.getElementById('deleteResponse').textContent = 'Error: Please enter a payload ID';
return;
}
const response = await fetch(`${API_BASE_URL}/v1/payloads/${payloadId}`, {
method: 'DELETE'
});
if (response.status === 204) {
document.getElementById('deleteResponse').innerHTML = '<span class="success">Payload deleted successfully</span>';
} else {
const text = await response.text();
document.getElementById('deleteResponse').innerHTML = `<span class="error">Error (${response.status}):</span><br><pre>${text}</pre>`;
}
} catch (error) {
document.getElementById('deleteResponse').innerHTML = `<span class="error">Error: ${error.message}</span>`;
}
});
</script>
</body>
</html>