diff --git a/src/types/api.ts b/src/types/api.ts new file mode 100644 index 0000000..0d77183 --- /dev/null +++ b/src/types/api.ts @@ -0,0 +1,65 @@ +//TypeScript types for API requests/responses +import { Item } from './database'; + +// API Request Types (matching your Rust structs) +export interface ItemRequest { + url: string; + item: Item; +} + +// API Response Types +export interface ApiResponse { + data?: T; + error?: string; + details?: string; + message?: string; +} + +export interface ItemsResponse { + items: Item[]; + selectedProperties: string[]; +} + +export interface ErrorResponse { + error: string; + details?: string; + url?: string; + itemId?: string; + property?: string; +} + +// API Success Responses +export interface ItemCreatedResponse { + message: string; + item: Item; +} + +export interface ItemDeletedResponse { + message: string; + itemId: string; +} + +export interface PropertyAddedResponse { + message: string; + property: string; +} + +export interface PropertyDeletedResponse { + message: string; + property: string; +} + +// HTTP Status Codes (for consistency) +export const HTTP_STATUS = { + OK: 200, + BAD_REQUEST: 400, + INTERNAL_SERVER_ERROR: 500, +} as const; + +// API Endpoints (for consistency) +export const API_ENDPOINTS = { + ITEMS: (encodedUrl: string) => `/api/urls/${encodedUrl}/items`, + ITEM: (encodedUrl: string, itemId: string) => `/api/urls/${encodedUrl}/items/${itemId}`, + PROPERTIES: (encodedUrl: string) => `/api/urls/${encodedUrl}/properties`, + PROPERTY: (encodedUrl: string, property: string) => `/api/urls/${encodedUrl}/properties/${property}`, +} as const; \ No newline at end of file