aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/lib/api.ts
diff options
context:
space:
mode:
authorzwlucas <lucas.fariamo08@gmail.com>2026-05-29 18:57:37 +0000
committerzwlucas <lucas.fariamo08@gmail.com>2026-05-29 18:57:37 +0000
commit6cc0bfd1d79074df790272b8091b1f0226d14283 (patch)
treecab18b0f708cf3b0eaeeeb98e2cf81459365b33e /frontend/src/lib/api.ts
downloadyaum-6cc0bfd1d79074df790272b8091b1f0226d14283.tar.gz
yaum-6cc0bfd1d79074df790272b8091b1f0226d14283.zip
feat: upload project
Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
Diffstat (limited to 'frontend/src/lib/api.ts')
-rw-r--r--frontend/src/lib/api.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts
new file mode 100644
index 0000000..0be9148
--- /dev/null
+++ b/frontend/src/lib/api.ts
@@ -0,0 +1,39 @@
+import type { Service, Heartbeat, ServiceStats } from './types';
+
+const BASE = '/api';
+
+export async function listServices(): Promise<Service[]> {
+ const res = await fetch(`${BASE}/services`);
+ if (!res.ok) throw new Error('falha ao listar serviços');
+ return res.json();
+}
+
+export async function createService(data: { name: string; url: string }): Promise<Service> {
+ const res = await fetch(`${BASE}/services`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(data)
+ });
+ if (!res.ok) {
+ const err = await res.json().catch(() => ({}));
+ throw new Error(err.error || 'falha ao criar serviço');
+ }
+ return res.json();
+}
+
+export async function deleteService(id: number): Promise<void> {
+ const res = await fetch(`${BASE}/services/${id}`, { method: 'DELETE' });
+ if (!res.ok) throw new Error('falha ao remover serviço');
+}
+
+export async function getHistory(id: number): Promise<Heartbeat[]> {
+ const res = await fetch(`${BASE}/services/${id}/history`);
+ if (!res.ok) throw new Error('falha ao obter histórico');
+ return res.json();
+}
+
+export async function getServiceStats(id: number): Promise<ServiceStats> {
+ const res = await fetch(`${BASE}/services/${id}/stats`);
+ if (!res.ok) throw new Error('falha ao obter estatísticas');
+ return res.json();
+}