1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00
pasty/web/assets/js/api.js

38 lines
980 B
JavaScript
Raw Normal View History

2020-08-24 22:53:23 +03:00
// apiBase defines the base URL of the API
const apiBase = location.protocol + "//" + location.host + "/api/v1";
2020-08-24 19:00:04 +03:00
// getAPIInformation returns the API information
export async function getAPIInformation() {
2020-08-24 22:53:23 +03:00
return fetch(apiBase + "/info");
2020-08-24 19:00:04 +03:00
}
// getPaste retrieves a paste
export async function getPaste(id) {
2020-08-24 22:53:23 +03:00
return fetch(apiBase + "/pastes/" + id);
2020-08-24 19:00:04 +03:00
}
// createPaste creates a new paste
export async function createPaste(content) {
2020-08-24 22:53:23 +03:00
return await fetch(apiBase + "/pastes", {
2020-08-24 19:00:04 +03:00
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
content
})
});
}
// deletePaste deletes a paste
export async function deletePaste(id, deletionToken) {
2020-08-24 22:53:23 +03:00
return await fetch(apiBase + "/pastes/" + id, {
2020-08-24 19:00:04 +03:00
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
deletionToken
})
});
}