Implemented article get endpoint
This commit is contained in:
18
js/api.js
18
js/api.js
@@ -28,7 +28,7 @@ async function login(username, password) {
|
||||
let result = await fetch(`${prefix}/api/login`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ "username": username, "password": password }),
|
||||
credentials: "include"
|
||||
credentials: "same-origin"
|
||||
});
|
||||
switch (result.status) {
|
||||
case 200:
|
||||
@@ -79,6 +79,22 @@ async function search(q) {
|
||||
throw unknownResponse(result);
|
||||
}
|
||||
}
|
||||
async function getArticle(id) {
|
||||
let query = [["id", id]];
|
||||
let result = await fetch(`${prefix}/api/article?${buildQuery(query)}`, {
|
||||
method: "GET"
|
||||
});
|
||||
switch (result.status) {
|
||||
case 200:
|
||||
return await result.json();
|
||||
case 401:
|
||||
throw new Error("Not authorized");
|
||||
case 404:
|
||||
throw new Error("Article not found");
|
||||
default:
|
||||
throw await unknownResponse(result);
|
||||
}
|
||||
}
|
||||
async function uploadArticle(payload) {
|
||||
let result = await fetch(`${prefix}/api/article`, {
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user