mirror of
https://github.com/nolanlawson/pinafore
synced 2024-12-13 10:48:19 +01:00
27 lines
640 B
JavaScript
27 lines
640 B
JavaScript
export async function post(url, body) {
|
|
return await (await fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Accept': 'application/json',
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(body)
|
|
})).json()
|
|
}
|
|
|
|
export function paramsString(paramsObject) {
|
|
let params = new URLSearchParams()
|
|
Object.keys(paramsObject).forEach(key => {
|
|
params.set(key, paramsObject[value])
|
|
})
|
|
return params.toString()
|
|
}
|
|
|
|
export async function get(url, headers = {}) {
|
|
return await (await fetch(url, {
|
|
method: 'GET',
|
|
headers: Object.assign(headers, {
|
|
'Accept': 'application/json',
|
|
})
|
|
})).json()
|
|
} |