32 lines
886 B
JavaScript
32 lines
886 B
JavaScript
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;
|
|
}
|