2022-04-15 17:04:23 +02:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
2023-06-20 07:03:15 +02:00
|
|
|
<title>Myco</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;
|
|
|
|
}
|
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%">
|
2022-04-18 22:07:52 +02:00
|
|
|
<fieldset>
|
|
|
|
<label for="bearer">bearer</label>
|
2022-04-19 16:49:30 +02:00
|
|
|
<input name="bearer" id="bearer"/>
|
2022-04-18 22:07:52 +02:00
|
|
|
</fieldset>
|
2022-04-17 22:15:09 +02:00
|
|
|
<fieldset>
|
|
|
|
<label for="op">Operation</label>
|
|
|
|
<select name="op" id="op">
|
2022-04-19 16:49:30 +02:00
|
|
|
<option></option>
|
|
|
|
<optgroup label="Api V1">
|
|
|
|
<option value="api-v1-sign-in">Api Sign In</option>
|
|
|
|
<option value="api-v1-products">Products</option>
|
|
|
|
<option value="api-v1-stocks">Stocks</option>
|
|
|
|
|
|
|
|
<option value="api-v1-shopping-cart">Shopping cart</option>
|
|
|
|
<option value="api-v1-shopping-cart-items">Shopping cart items</option>
|
|
|
|
</optgroup>
|
|
|
|
<optgroup label="Admin">
|
|
|
|
<option value="admin-auto-login">Auto login</option>
|
|
|
|
<option value="admin-get-products">Get products</option>
|
|
|
|
<option value="admin-create-product">Create product</option>
|
|
|
|
<option value="admin-create-stock">Create stock</option>
|
|
|
|
</optgroup>
|
|
|
|
|
2022-04-17 22:15:09 +02:00
|
|
|
</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>
|
2022-04-19 16:49:30 +02:00
|
|
|
<label for="params">Params</label>
|
|
|
|
<textarea id="params" rows="40"></textarea>
|
2022-04-16 21:09:50 +02:00
|
|
|
</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');
|
2022-04-18 22:07:52 +02:00
|
|
|
const bearerEl = form.querySelector('#bearer');
|
2022-04-17 22:15:09 +02:00
|
|
|
|
|
|
|
const send = (method, path, params) => {
|
2022-04-18 22:07:52 +02:00
|
|
|
const bearer = bearerEl.value || '';
|
|
|
|
|
2022-04-17 22:15:09 +02:00
|
|
|
const rest = method === 'GET'
|
|
|
|
? {}
|
|
|
|
: { body: JSON.stringify(params), headers: { 'Content-Type': 'application/json' } };
|
2022-04-18 22:07:52 +02:00
|
|
|
|
|
|
|
if (bearer.length) {
|
|
|
|
if (!rest.headers) rest.headers = {};
|
2022-04-19 16:49:30 +02:00
|
|
|
rest.headers["Authorization"] = `Bearer ${ bearer }`;
|
2022-04-18 22:07:52 +02:00
|
|
|
}
|
|
|
|
|
2022-04-17 22:15:09 +02:00
|
|
|
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) {
|
2022-04-19 16:49:30 +02:00
|
|
|
case 'api-v1-sign-in': {
|
|
|
|
mthEl.value = 'POST';
|
|
|
|
urlEl.value = '/api/v1/sign-in';
|
|
|
|
paramsEl.value = 'login=Eraden\npassword=test';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'api-v1-products': {
|
|
|
|
mthEl.value = 'GET';
|
|
|
|
urlEl.value = '/api/v1/products';
|
|
|
|
paramsEl.value = '';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'api-v1-stocks': {
|
|
|
|
mthEl.value = 'GET';
|
|
|
|
urlEl.value = '/api/v1/stocks';
|
|
|
|
paramsEl.value = '';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'api-v1-shopping-cart': {
|
|
|
|
mthEl.value = 'GET';
|
|
|
|
urlEl.value = '/api/v1/shopping-cart';
|
|
|
|
paramsEl.value = '';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'api-v1-shopping-cart-items': {
|
|
|
|
mthEl.value = 'GET';
|
|
|
|
urlEl.value = '/api/v1/shopping-cart-items';
|
|
|
|
paramsEl.value = '';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// admin
|
|
|
|
case 'admin-auto-login': {
|
|
|
|
paramsEl.value = `login=Eraden\npassword=test`
|
2022-04-17 23:11:58 +02:00
|
|
|
mthEl.value = 'POST';
|
|
|
|
urlEl.value = '/admin/sign-in';
|
|
|
|
break;
|
|
|
|
}
|
2022-04-19 16:49:30 +02:00
|
|
|
case 'admin-get-products': {
|
2022-04-17 23:11:58 +02:00
|
|
|
mthEl.value = 'GET';
|
|
|
|
urlEl.value = '/admin/api/v1/products';
|
2022-04-19 16:49:30 +02:00
|
|
|
paramsEl.value = '';
|
2022-04-17 23:11:58 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-04-19 16:49:30 +02:00
|
|
|
case 'admin-create-product': {
|
|
|
|
paramsEl.value = serializeParams({
|
2022-04-17 22:15:09 +02:00
|
|
|
name: 'Foo',
|
|
|
|
short_description: 'asd',
|
|
|
|
long_description: 'asjdoiajd ajio djaso idja s',
|
2022-04-19 16:49:30 +02:00
|
|
|
price: 1200,
|
|
|
|
deliver_days_flag: ["monday"]
|
|
|
|
});
|
2022-04-17 23:11:58 +02:00
|
|
|
mthEl.value = 'POST';
|
|
|
|
urlEl.value = '/admin/api/v1/product';
|
|
|
|
break;
|
|
|
|
}
|
2022-04-19 16:49:30 +02:00
|
|
|
case 'admin-create-stock': {
|
|
|
|
paramsEl.value = serializeParams({
|
|
|
|
product_id: 1,
|
|
|
|
quantity: 456,
|
|
|
|
quantity_unit: 'gram'
|
|
|
|
});
|
|
|
|
mthEl.value = 'POST';
|
|
|
|
urlEl.value = '/admin/api/v1/stock';
|
|
|
|
break;
|
|
|
|
}
|
2022-04-17 22:15:09 +02:00
|
|
|
}
|
2022-04-19 16:49:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const serializeParams = (p) =>
|
|
|
|
Object.entries(p).map(([k, v]) => {
|
|
|
|
let value = Array.isArray(v)
|
|
|
|
? `[${ v.join(',') }]`
|
|
|
|
: v
|
|
|
|
return `${ k }=${ value }`
|
|
|
|
}).join('\n');
|
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 {
|
2022-04-19 16:49:30 +02:00
|
|
|
if (v.match(/\-?\d+/)) {
|
|
|
|
v = JSON.parse(v);
|
|
|
|
} else if (v.startsWith("[") && v.endsWith(']')) {
|
|
|
|
v = v.substring(1, v.length - 1).split(',').map(s => s.trim())
|
|
|
|
}
|
2022-04-17 22:15:09 +02:00
|
|
|
} 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>
|