Browse Source

add a slash before the path and a questionmark before the querystring

master
Maurits Lourens 5 years ago
parent
commit
8709fb2f0b
  1. 6
      packages/builder/src/components/integration/index.svelte
  2. 14
      packages/server/src/integrations/rest.ts

6
packages/builder/src/components/integration/index.svelte

@ -17,9 +17,9 @@
$: urlDisplay = $: urlDisplay =
schema.urlDisplay && schema.urlDisplay &&
`${datasource.config.url}${query.fields.path ?? ""}${ `${datasource.config.url}${
query.fields.queryString ?? "" query.fields.path ? "/" + query.fields.path : ""
}` }${query.fields.queryString ? "?" + query.fields.queryString : ""}`
function updateQuery({ detail }) { function updateQuery({ detail }) {
query.fields[schema.type] = detail.value query.fields[schema.type] = detail.value

14
packages/server/src/integrations/rest.ts

@ -152,13 +152,17 @@ module RestModule {
} }
} }
getUrl(path: string, queryString: string): string {
return `${this.config.url}/${path}?${queryString}`
}
async create({ path = "", queryString = "", headers = {}, json = {} }) { async create({ path = "", queryString = "", headers = {}, json = {} }) {
this.headers = { this.headers = {
...this.config.defaultHeaders, ...this.config.defaultHeaders,
...headers, ...headers,
} }
const response = await fetch(this.config.url + path + queryString, { const response = await fetch(this.getUrl(path, queryString), {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify(json), body: JSON.stringify(json),
@ -173,7 +177,7 @@ module RestModule {
...headers, ...headers,
} }
const response = await fetch(this.config.url + path + queryString, { const response = await fetch(this.getUrl(path, queryString), {
headers: this.headers, headers: this.headers,
}) })
@ -186,7 +190,7 @@ module RestModule {
...headers, ...headers,
} }
const response = await fetch(this.config.url + path + queryString, { const response = await fetch(this.getUrl(path, queryString), {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
body: JSON.stringify(json), body: JSON.stringify(json),
@ -201,7 +205,7 @@ module RestModule {
...headers, ...headers,
} }
const response = await fetch(this.config.url + path + queryString, { const response = await fetch(this.getUrl(path, queryString), {
method: "PATCH", method: "PATCH",
headers: this.headers, headers: this.headers,
body: JSON.stringify(json), body: JSON.stringify(json),
@ -216,7 +220,7 @@ module RestModule {
...headers, ...headers,
} }
const response = await fetch(this.config.url + path + queryString, { const response = await fetch(this.getUrl(path, queryString), {
method: "DELETE", method: "DELETE",
headers: this.headers, headers: this.headers,
}) })

Loading…
Cancel
Save