A very performant and light (2mb in memory) link shortener and tracker. Written in Rust and React and uses Postgres/SQLite.
1import axios from 'axios'; 2import { CreateLinkRequest, Link, AuthResponse } from '../types/api'; 3 4// Create axios instance with default config 5const api = axios.create({ 6 baseURL: '/api', 7}); 8 9// Add a request interceptor to add the auth token to all requests 10api.interceptors.request.use((config) => { 11 const token = localStorage.getItem('token'); 12 if (token) { 13 config.headers.Authorization = `Bearer ${token}`; 14 } 15 return config; 16}); 17 18// Auth endpoints 19export const login = async (email: string, password: string) => { 20 const response = await api.post<AuthResponse>('/auth/login', { 21 email, 22 password, 23 }); 24 return response.data; 25}; 26 27export const register = async (email: string, password: string) => { 28 const response = await api.post<AuthResponse>('/auth/register', { 29 email, 30 password, 31 }); 32 return response.data; 33}; 34 35// Protected endpoints 36export const createShortLink = async (data: CreateLinkRequest) => { 37 const response = await api.post<Link>('/shorten', data); 38 return response.data; 39}; 40 41export const getAllLinks = async () => { 42 const response = await api.get<Link[]>('/links'); 43 return response.data; 44}; 45 46export const deleteLink = async (id: number) => { 47 await api.delete(`/links/${id}`); 48};