2020-10-25 00:11:08 -07:00
|
|
|
<template>
|
2021-04-12 20:43:19 -07:00
|
|
|
<div class="_root">
|
|
|
|
<div class="_block" style="padding: 24px;">
|
2021-09-29 08:50:45 -07:00
|
|
|
<MkInput v-model="endpoint" :datalist="endpoints" @update:modelValue="onEndpointChange()" class="">
|
2021-08-06 06:29:19 -07:00
|
|
|
<template #label>Endpoint</template>
|
2021-04-12 20:43:19 -07:00
|
|
|
</MkInput>
|
2021-08-06 06:29:19 -07:00
|
|
|
<MkTextarea v-model="body" code>
|
|
|
|
<template #label>Params (JSON or JSON5)</template>
|
2021-04-12 20:43:19 -07:00
|
|
|
</MkTextarea>
|
2021-08-06 06:29:19 -07:00
|
|
|
<MkSwitch v-model="withCredential">
|
2021-04-12 20:43:19 -07:00
|
|
|
With credential
|
|
|
|
</MkSwitch>
|
|
|
|
<MkButton primary full @click="send" :disabled="sending">
|
|
|
|
<template v-if="sending"><MkEllipsis/></template>
|
2021-04-20 07:22:59 -07:00
|
|
|
<template v-else><i class="fas fa-paper-plane"></i> Send</template>
|
2021-04-12 20:43:19 -07:00
|
|
|
</MkButton>
|
2021-04-11 05:31:38 -07:00
|
|
|
</div>
|
2021-04-12 20:43:19 -07:00
|
|
|
<div v-if="res" class="_block" style="padding: 24px;">
|
2021-08-06 06:29:19 -07:00
|
|
|
<MkTextarea v-model="res" code readonly tall>
|
|
|
|
<template #label>Response</template>
|
2021-04-12 20:43:19 -07:00
|
|
|
</MkTextarea>
|
2021-04-11 05:31:38 -07:00
|
|
|
</div>
|
2020-10-25 00:11:08 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
import * as JSON5 from 'json5';
|
2021-03-23 01:30:14 -07:00
|
|
|
import MkButton from '@client/components/ui/button.vue';
|
2021-09-29 08:50:45 -07:00
|
|
|
import MkInput from '@client/components/form/input.vue';
|
|
|
|
import MkTextarea from '@client/components/form/textarea.vue';
|
|
|
|
import MkSwitch from '@client/components/form/switch.vue';
|
2021-03-23 01:30:14 -07:00
|
|
|
import * as os from '@client/os';
|
2021-04-09 20:54:12 -07:00
|
|
|
import * as symbols from '@client/symbols';
|
2020-10-25 00:11:08 -07:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
MkButton, MkInput, MkTextarea, MkSwitch,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-09 20:54:12 -07:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-11-03 03:36:12 -08:00
|
|
|
title: 'API console',
|
2021-04-20 07:22:59 -07:00
|
|
|
icon: 'fas fa-terminal'
|
2020-10-25 00:11:08 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
endpoint: '',
|
|
|
|
body: '{}',
|
|
|
|
res: null,
|
|
|
|
sending: false,
|
|
|
|
endpoints: [],
|
|
|
|
withCredential: true,
|
|
|
|
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
os.api('endpoints').then(endpoints => {
|
|
|
|
this.endpoints = endpoints;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
send() {
|
|
|
|
this.sending = true;
|
|
|
|
os.api(this.endpoint, JSON5.parse(this.body)).then(res => {
|
|
|
|
this.sending = false;
|
|
|
|
this.res = JSON5.stringify(res, null, 2);
|
|
|
|
}, err => {
|
|
|
|
this.sending = false;
|
|
|
|
this.res = JSON5.stringify(err, null, 2);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onEndpointChange() {
|
|
|
|
os.api('endpoint', { endpoint: this.endpoint }, this.withCredential ? undefined : null).then(endpoint => {
|
|
|
|
const body = {};
|
|
|
|
for (const p of endpoint.params) {
|
|
|
|
body[p.name] =
|
|
|
|
p.type === 'String' ? '' :
|
|
|
|
p.type === 'Number' ? 0 :
|
|
|
|
p.type === 'Boolean' ? false :
|
|
|
|
p.type === 'Array' ? [] :
|
|
|
|
p.type === 'Object' ? {} :
|
|
|
|
null;
|
|
|
|
}
|
|
|
|
this.body = JSON5.stringify(body, null, 2);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|