Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TypeScript Request and Response Types #19

Open
lazarevtill opened this issue Apr 6, 2025 · 0 comments
Open

Implement TypeScript Request and Response Types #19

lazarevtill opened this issue Apr 6, 2025 · 0 comments

Comments

@lazarevtill
Copy link
Contributor

Implement TypeScript Request and Response Types

Problem:
API routes lack consistent typing for request and response data.

Recommendation:
Define strict TypeScript interfaces for all API requests and responses.

// Create app/types/api.ts
export namespace API {
  // Chat API
  export namespace Chat {
    export interface Request {
      messages: Message[];
      chatId: string;
      userId: string;
      model: string;
      isAuthenticated: boolean;
      systemPrompt: string;
    }
    
    export interface Response {
      messageId?: string;
      error?: string;
      code?: string;
    }
  }
  
  // Rate limits API
  export namespace RateLimits {
    export interface Request {
      userId: string;
      isAuthenticated: boolean;
    }
    
    export interface Response {
      dailyCount: number;
      dailyLimit: number;
      remaining: number;
    }
  }
  
  // Add more API types...
}

// Use in API routes
import { API } from "@/app/types/api";

export async function POST(req: Request) {
  const requestData = await req.json() as API.Chat.Request;
  
  // Process request...
  
  const response: API.Chat.Response = {
    messageId: "123",
  };
  
  return new Response(JSON.stringify(response));
}

Impact: Medium - Improves type safety and code maintainability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant