aboutsummaryrefslogtreecommitdiff
path: root/src/routes/todos/_api.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/todos/_api.ts')
-rw-r--r--src/routes/todos/_api.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/routes/todos/_api.ts b/src/routes/todos/_api.ts
new file mode 100644
index 0000000..f8bcf73
--- /dev/null
+++ b/src/routes/todos/_api.ts
@@ -0,0 +1,22 @@
+/*
+ This module is used by the /todos and /todos/[uid]
+ endpoints to make calls to api.svelte.dev, which stores todos
+ for each user. The leading underscore indicates that this is
+ a private module, _not_ an endpoint — visiting /todos/_api
+ will net you a 404 response.
+
+ (The data on the todo app will expire periodically; no
+ guarantees are made. Don't use it to organise your life.)
+*/
+
+const base = 'https://api.svelte.dev';
+
+export async function api(request: Request, resource: string, data?: Record<string, unknown>) {
+ return fetch(`${base}/${resource}`, {
+ method: request.method,
+ headers: {
+ 'content-type': 'application/json'
+ },
+ body: data && JSON.stringify(data)
+ });
+}