2022-04-15 17:04:23 +02:00
|
|
|
<!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;
|
|
|
|
}
|
2022-04-17 22:15:09 +02:00
|
|
|
|
2022-04-16 21:09:50 +02:00
|
|
|
fieldset > label {
|
|
|
|
width: 45%;
|
|
|
|
}
|
2022-04-17 22:15:09 +02:00
|
|
|
|
2022-04-16 21:09:50 +02:00
|
|
|
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">
|
2022-04-15 17:04:23 +02:00
|
|
|
</head>
|
|
|
|
<body>
|
2022-04-16 21:09:50 +02:00
|
|
|
<div style="display: flex;justify-content: space-between;">
|
|
|
|
<div style="width: 49%">
|
2022-04-17 22:15:09 +02:00
|
|
|
<form style="width: 100%">
|
|
|
|
<fieldset>
|
|
|
|
<label for="op">Operation</label>
|
|
|
|
<select name="op" id="op">
|
|
|
|
<option value="auto-login">Auto login</option>
|
|
|
|
<option value="get-products">Get products</option>
|
|
|
|
<option value="create-product">Create product</option>
|
|
|
|
</select>
|
|
|
|
</fieldset>
|
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>
|
2022-04-15 17:04:23 +02:00
|
|
|
<input type="submit">
|
|
|
|
</form>
|
|
|
|
</div>
|
2022-04-16 21:09:50 +02:00
|
|
|
<div style="width: 49%">
|
2022-04-17 22:15:09 +02:00
|
|
|
<pre style="background: black; width: 100%; min-height: 300px"><code
|
|
|
|
id="output"
|
|
|
|
class="language-json"
|
|
|
|
style="overflow: auto"
|
|
|
|
></code></pre>
|
2022-04-15 17:04:23 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
2022-04-16 21:09:50 +02:00
|
|
|
Prism.manual = true;
|
|
|
|
|
2022-04-15 17:04:23 +02:00
|
|
|
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');
|
2022-04-17 22:15:09 +02:00
|
|
|
const opEL = form.querySelector('#op');
|
|
|
|
|
|
|
|
const send = (method, path, params) => {
|
|
|
|
const rest = method === 'GET'
|
|
|
|
? {}
|
|
|
|
: { body: JSON.stringify(params), headers: { 'Content-Type': 'application/json' } };
|
|
|
|
path = method === 'GET'
|
|
|
|
? `${ path }?${ JSON.stringify(params) }`
|
|
|
|
: path;
|
|
|
|
|
|
|
|
fetch(`${ path }`, { ...rest, method })
|
|
|
|
.then(async (res) => {
|
|
|
|
if (res.status < 400) {
|
|
|
|
const json = await res.json();
|
|
|
|
out.innerHTML = Prism.highlight(JSON.stringify(json, null, 4), Prism.languages.json, 'json');
|
|
|
|
} else {
|
|
|
|
out.innerHTML = await res.text();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
opEL.addEventListener('change', () => {
|
|
|
|
switch (opEL.value) {
|
|
|
|
case 'auto-login':
|
|
|
|
paramsEl.value = `login=Eraden\npassword=text`
|
|
|
|
return send(mthEl.value = 'POST', urlEl.value = '/admin/sign-in', { login: 'Eraden', password: 'test' })
|
|
|
|
case 'get-products':
|
|
|
|
return send(mthEl.value = 'GET', urlEl.value = '/admin/api/v1/products', {})
|
|
|
|
case 'create-product':
|
|
|
|
const p = {
|
|
|
|
name: 'Foo',
|
|
|
|
short_description: 'asd',
|
|
|
|
long_description: 'asjdoiajd ajio djaso idja s',
|
|
|
|
price_major: 12,
|
|
|
|
price_minor: 0,
|
|
|
|
};
|
|
|
|
paramsEl.value = Object.entries(p).map((k, v) => `${ k }=${ v }}`).join('\n');
|
|
|
|
return send(mthEl.value = 'POST', urlEl.value = '/admin/api/v1/product', p)
|
|
|
|
}
|
|
|
|
})
|
2022-04-15 17:04:23 +02:00
|
|
|
|
|
|
|
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 => {
|
2022-04-15 17:04:23 +02:00
|
|
|
if (!s.length) return;
|
2022-04-16 21:09:50 +02:00
|
|
|
let [k, ...v] = s.split("=");
|
2022-04-17 22:15:09 +02:00
|
|
|
v = Array(v).join('=')
|
|
|
|
try {
|
|
|
|
v = JSON.parse(v);
|
|
|
|
} catch (_) {
|
|
|
|
}
|
|
|
|
params[k] = v;
|
2022-04-15 17:04:23 +02:00
|
|
|
});
|
|
|
|
|
2022-04-17 22:15:09 +02:00
|
|
|
send(method, path, params)
|
2022-04-15 17:04:23 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|