Hook up API calls with Axios

This commit is contained in:
2025-12-24 13:01:34 +00:00
parent ca34727c79
commit c56ea8b90f
7 changed files with 146 additions and 34 deletions

27
frontend/app/utils/api.ts Normal file
View File

@@ -0,0 +1,27 @@
import axios from "axios";
const API_BASE_URL = "http://localhost:8080";
export async function shortenLink(longUrl: string): Promise<{
shortUrl: string;
manageUrl: string;
}> {
let res = await axios.post(API_BASE_URL + "/l", {
url: longUrl,
title: "Unnamed",
});
let sl: {
id: string;
url: string;
code: string;
title: string;
createdAt: string;
clicks: number;
} = res.data
return {
shortUrl: API_BASE_URL + "/l/" + sl.code,
manageUrl: API_BASE_URL + "/l/" + sl.code + "/manage",
}
}

View File

@@ -1,10 +0,0 @@
export async function shortenLink(longUrl: string): Promise<{
shortUrl: string;
manageUrl: string;
}> {
let randomText = Math.random().toString(36).substring(2, 8);
return {
shortUrl: "https://halflink.example/" + randomText,
manageUrl: "https://halflink.example/" + randomText + "/manage",
}
}