This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { fetchJson } from '../../shared/api/http.js';
|
||||
|
||||
export async function getArticles() {
|
||||
const response = await fetchJson('/api/articles');
|
||||
return response.articles;
|
||||
}
|
||||
|
||||
export async function createArticle(article) {
|
||||
const response = await fetchJson('/api/articles', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ article }),
|
||||
});
|
||||
|
||||
return response.article;
|
||||
}
|
||||
|
||||
export async function updateArticle(slug, article) {
|
||||
const response = await fetchJson(`/api/articles/${encodeURIComponent(slug)}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ article }),
|
||||
});
|
||||
|
||||
return response.article;
|
||||
}
|
||||
|
||||
export async function deleteArticle(slug) {
|
||||
const response = await fetchJson(`/api/articles/${encodeURIComponent(slug)}`, { method: 'DELETE' });
|
||||
return response.article;
|
||||
}
|
||||
Reference in New Issue
Block a user