You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All API responses follow a consistent structure to simplify frontend handling and provide a great developer experience.
Response Structure
interfaceApiResponse<T=unknown>{ok: boolean;// Quick success checkcode: number;// Numeric status codetype: ResponseType;// "success" | "error" | "warning"title: string;// Short title for UImessage: string;// Detailed message for userdata: T|null;// Response payloaderrors: ValidationError[]|null;// Field-level errorsmeta: ResponseMeta;// Pagination/extra infotimestamp: string;// ISO 8601 timestamptraceId?: string;// Optional request trace ID}
Validation Error Structure
interfaceValidationError{field: string;// Field name (e.g., "email", "password")rule: string;// Rule that failed (e.g., "required", "minLength")message: string;// Human-readable message}
Response Meta Structure
interfaceResponseMeta{page?: number;// Current page (1-indexed)perPage?: number;// Items per pagetotal?: number;// Total itemstotalPages?: number;// Total pages[key: string]: unknown;// Additional context}
constresponse=awaithttpGet<User>("/api/users/123");if(response.ok){// Success - data is typed as Userconsole.log(response.data?.name);}else{// Error - show message to usershowToast(response.title,response.message,"error");}
Handling Validation Errors
constresponse=awaithttpPost<User>("/api/users",formData);if(!response.ok&&response.errors){// Map errors to form fieldsresponse.errors.forEach((error)=>{setFieldError(error.field,error.message);});}