Merge branch 'master' of https://github.com/liyasthomas/postwoman
This commit is contained in:
@@ -63,7 +63,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="path">Path</label>
|
<label for="path">Path</label>
|
||||||
<input @keyup.enter="isValidURL ? sendRequest() : null" id="path" name="path" v-model="path">
|
<input @keyup.enter="isValidURL ? sendRequest() : null" id="path" name="path" v-model="path" @input="pathInputHandler">
|
||||||
</li>
|
</li>
|
||||||
<div class="show-on-small-screen">
|
<div class="show-on-small-screen">
|
||||||
<li>
|
<li>
|
||||||
@@ -450,6 +450,7 @@
|
|||||||
body: ''
|
body: ''
|
||||||
},
|
},
|
||||||
previewEnabled: false,
|
previewEnabled: false,
|
||||||
|
paramsWatchEnabled: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These are content types that can be automatically
|
* These are content types that can be automatically
|
||||||
@@ -499,6 +500,32 @@
|
|||||||
responseText.innerText = this.response.body
|
responseText.innerText = this.response.body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
handler: function(newValue) {
|
||||||
|
if(!this.paramsWatchEnabled) {
|
||||||
|
this.paramsWatchEnabled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let path = this.path;
|
||||||
|
let queryString = newValue
|
||||||
|
.filter(({
|
||||||
|
key
|
||||||
|
}) => !!key)
|
||||||
|
.map(({
|
||||||
|
key,
|
||||||
|
value
|
||||||
|
}) => `${key}=${value}`).join('&')
|
||||||
|
queryString = queryString === '' ? '' : `?${queryString}`
|
||||||
|
if(path.indexOf('?') !== -1) {
|
||||||
|
path = path.slice(0, path.indexOf('?')) + queryString;
|
||||||
|
} else {
|
||||||
|
path = path + queryString
|
||||||
|
}
|
||||||
|
|
||||||
|
this.path = path;
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -517,6 +544,9 @@
|
|||||||
hasRequestBody() {
|
hasRequestBody() {
|
||||||
return ['POST', 'PUT', 'PATCH'].includes(this.method);
|
return ['POST', 'PUT', 'PATCH'].includes(this.method);
|
||||||
},
|
},
|
||||||
|
pathName() {
|
||||||
|
return this.path.match(/^([^?]*)\??/)[1]
|
||||||
|
},
|
||||||
rawRequestBody() {
|
rawRequestBody() {
|
||||||
const {
|
const {
|
||||||
bodyParams
|
bodyParams
|
||||||
@@ -721,7 +751,7 @@
|
|||||||
try {
|
try {
|
||||||
const payload = await this.$axios({
|
const payload = await this.$axios({
|
||||||
method: this.method,
|
method: this.method,
|
||||||
url: this.url + this.path + this.queryString,
|
url: this.url + this.pathName + this.queryString,
|
||||||
auth,
|
auth,
|
||||||
headers,
|
headers,
|
||||||
data: requestBody ? requestBody.toString() : null
|
data: requestBody ? requestBody.toString() : null
|
||||||
@@ -771,7 +801,36 @@
|
|||||||
this.response.body = "See JavaScript console (F12) for details.";
|
this.response.body = "See JavaScript console (F12) for details.";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getQueryStringFromPath() {
|
||||||
|
let path = this.path,
|
||||||
|
hashIndex = path.indexOf('#'),
|
||||||
|
start = path.indexOf('?'),
|
||||||
|
end = hashIndex !== -1 ? hashIndex : path.length,
|
||||||
|
queryString = '';
|
||||||
|
|
||||||
|
if(start !== -1) {
|
||||||
|
let sliced = path.slice(start, end);
|
||||||
|
queryString = sliced.length > 1 ? sliced : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryString;
|
||||||
|
},
|
||||||
|
queryStringToArray(queryString) {
|
||||||
|
return queryString.replace(/^\?/, '').split('&').filter(pair => !!pair).map(pair => {
|
||||||
|
let splited = pair.replace(/#/g, '').split('=');
|
||||||
|
return {
|
||||||
|
key: splited.shift(),
|
||||||
|
value: splited.join('=')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
pathInputHandler() {
|
||||||
|
let queryString = this.getQueryStringFromPath(),
|
||||||
|
params = this.queryStringToArray(queryString);
|
||||||
|
|
||||||
|
this.paramsWatchEnabled = false;
|
||||||
|
this.params = params;
|
||||||
|
},
|
||||||
addRequestHeader() {
|
addRequestHeader() {
|
||||||
this.headers.push({
|
this.headers.push({
|
||||||
key: '',
|
key: '',
|
||||||
|
|||||||
Reference in New Issue
Block a user