bazzar/api/assets/index.html

96 lines
3.1 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bazzar</title>
2022-04-16 21:09:50 +02:00
<style>
@import url(https://fonts.googleapis.com/css?family=Questrial);
@import url(https://fonts.googleapis.com/css?family=Arvo);
@font-face {
src: url(https://lea.verou.me/logo.otf);
font-family: 'LeaVerou';
}
fieldset {
display: flex;
justify-content: space-between;
width: 600px;
}
fieldset > label {
width: 45%;
}
fieldset > input, fieldset > textarea {
width: 54%;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.27.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.27.0/components/prism-json.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.27.0/themes/prism-dark.min.css">
</head>
<body>
2022-04-16 21:09:50 +02:00
<div style="display: flex;justify-content: space-between;">
<div style="width: 49%">
<form>
2022-04-16 21:09:50 +02:00
<fieldset>
<label for="method">Method</label>
<select id="method">
<option value="GET">GET</option>
<option value="POST">POST</option>
<option value="PATCH">PATCH</option>
<option value="DELETE">DELETE</option>
</select>
</fieldset>
<fieldset>
<label for="path">Path</label><input id="path" type="text">
</fieldset>
<fieldset>
<label for="params">Params</label><textarea id="params"></textarea>
</fieldset>
<input type="submit">
</form>
</div>
2022-04-16 21:09:50 +02:00
<div style="width: 49%">
<pre style="background: black; width: 100%; min-height: 300px"><code id="output" class="language-json"></code></pre>
</div>
</div>
<script>
2022-04-16 21:09:50 +02:00
Prism.manual = true;
const out = document.querySelector('#output');
const form = document.querySelector("form");
const urlEl = form.querySelector('#path');
const paramsEl = form.querySelector('#params');
const mthEl = form.querySelector('#method');
form.addEventListener('submit', (ev) => {
ev.preventDefault();
ev.stopPropagation();
let path = urlEl.value;
let params = {};
const method = mthEl.value;
2022-04-16 20:20:59 +02:00
paramsEl.value.split("\n").forEach(s => {
if (!s.length) return;
2022-04-16 21:09:50 +02:00
let [k, ...v] = s.split("=");
params[k] = Array(v).join('=');
});
const rest = method === 'GET'
? {}
: { body: JSON.stringify(params), headers: { 'Content-Type': 'application/json' } };
path = method === 'GET'
? `${ path }?${ JSON.stringify(params) }`
: path;
2022-04-16 21:09:50 +02:00
fetch(`${ path }`, { ...rest, method })
.then(res => res.json())
.then(json => {
2022-04-16 21:09:50 +02:00
out.innerHTML = Prism.highlight(JSON.stringify(json), Prism.languages.json, 'json');
})
});
</script>
</body>
</html>