export const apiUrl = "http://127.0.0.1:3001" const defaults = { headers: {'Content-Type': 'application/json'} }; export async function postNewPage() { return fetch(`${apiUrl}/page/new`, { method: 'POST', ...defaults }).then((res) => res.json()) .then((data) => data.id) } export async function fetchPageList() { return fetch(`${apiUrl}/pages`, { method: 'GET', ...defaults }).then((res) => res.json()) } export async function fetchPage(id) { return fetch(`${apiUrl}/page/${id}`, { method: 'GET', ...defaults }).then((res) => res.json()) } export async function postPage({id, title, description}) { return fetch(`${apiUrl}/page/${id}`, { method: 'POST', body: JSON.stringify({id: id, title: title, description: description}), ...defaults }) } export async function deletePage(id) { return fetch(`${apiUrl}/page/${id}`, { method: 'DELETE', headers: {'Content-Type': 'application/json'}, ...defaults }) }