Added voting. Improved comments.
This commit is contained in:
@@ -14,7 +14,7 @@ function getQuery(data) {
|
||||
return `?${new URLSearchParams(data).toString()}`;
|
||||
}
|
||||
|
||||
export async function get(path, query = {}) {
|
||||
async function get(path, query = {}) {
|
||||
const res = await fetch(`/api${path}${getQuery(query)}`);
|
||||
const body = await res.json();
|
||||
|
||||
@@ -25,7 +25,7 @@ export async function get(path, query = {}) {
|
||||
throw new Error(body.message);
|
||||
}
|
||||
|
||||
export async function post(path, data, { query } = {}) {
|
||||
async function post(path, data, { query } = {}) {
|
||||
const res = await fetch(`/api${path}${getQuery(query)}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
@@ -45,7 +45,7 @@ export async function post(path, data, { query } = {}) {
|
||||
throw new Error(body.statusMessage);
|
||||
}
|
||||
|
||||
export async function patch(path, data, { query } = {}) {
|
||||
async function patch(path, data, { query } = {}) {
|
||||
const res = await fetch(`/api${path}${getQuery(query)}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(data),
|
||||
@@ -65,7 +65,7 @@ export async function patch(path, data, { query } = {}) {
|
||||
throw new Error(body.message);
|
||||
}
|
||||
|
||||
export async function del(path, { data, query } = {}) {
|
||||
async function del(path, { data, query } = {}) {
|
||||
const res = await fetch(`/api${path}${getQuery(query)}`, {
|
||||
method: 'DELETE',
|
||||
body: JSON.stringify(data),
|
||||
@@ -84,3 +84,10 @@ export async function del(path, { data, query } = {}) {
|
||||
|
||||
throw new Error(body.message);
|
||||
}
|
||||
|
||||
export {
|
||||
get,
|
||||
post,
|
||||
patch,
|
||||
del,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// centralize navigation to simplify switching between client and server routing
|
||||
export default function navigate(path) {
|
||||
export function navigate(path) {
|
||||
window.location.href = path;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user