Skip to content

[WIP] Add new REST endpoint GET /api/routes for API discovery#1

Closed
Copilot wants to merge 1 commit into
masterfrom
copilot/add-api-routes-endpoint
Closed

[WIP] Add new REST endpoint GET /api/routes for API discovery#1
Copilot wants to merge 1 commit into
masterfrom
copilot/add-api-routes-endpoint

Conversation

Copilot AI commented Nov 17, 2025

Copy link
Copy Markdown

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Implement a new REST endpoint GET /api/routes in the repository Sushant0753/AI-Assistant.

Goal:
Provide a consolidated list of all public API endpoints served by the application so that clients (and future auto-documentation tooling) can discover capabilities programmatically.

Requirements:

  1. Create a new route handler mounted at /api/routes that returns JSON.
  2. Response shape:
    {
    "routes": [
    { "method": "GET", "path": "/api/routes" },
    { "method": "GET", "path": "/api/health" },
    ... other routes ...
    ],
    "generatedAt": "2025-11-17T15:10:10.000Z"
    }
  3. The list of routes should be generated automatically from the Express (or chosen framework) app/router configuration rather than hard-coded, if the project uses Express. If automatic introspection is not feasible with current framework, create a central route registration module that exports an array describing each route and reuse it both for registration and for /api/routes output.
  4. Add TypeScript types for the route descriptor: interface ApiRoute { method: string; path: string; description?: string }
  5. Ensure the endpoint is CORS-safe if the project already configures CORS (reuse existing middleware).
  6. Include basic tests:
    • Unit test verifying that GET /api/routes returns 200 and a non-empty routes array containing itself.
    • Test that each route object has method and path.
  7. Update any existing README or API documentation section to mention the new discovery endpoint.
  8. If there is no existing server entry point, create one (e.g., src/server.ts) using Express with an example additional route (e.g., /api/health) so /api/routes has at least two entries.
  9. Follow existing code style: prefer TypeScript, ES modules (or CommonJS) matching repository convention, and run any existing lint scripts.
  10. Do not break existing functionality; ensure build passes.

Implementation Outline (adjust to existing structure after inspecting repo):

  • Introduce a route registry module: src/api/routeRegistry.ts exporting an array of ApiRoute and a function to register routes to an Express Router.
  • /api/routes handler reads the registry and returns JSON with timestamp.
  • If Express app already exists, enhance it; otherwise scaffold minimal Express app with routes.
  • Add tests in a new test file (e.g., tests/routes.spec.ts) using chosen test framework (Jest assumed if present). If no test framework, add Jest config minimally.

Edge Cases / Notes:

  • Ensure duplicate route entries are filtered out.
  • Support future extension for descriptions and versioning.
  • Avoid including internal or non-API routes (like static file serving) unless they fall under /api/ prefix.

Deliverables:

  • New/updated TypeScript source files implementing /api/routes.
  • Tests passing locally.
  • README updated with example response.

Please inspect the repository to adapt file paths (e.g., src/, server/, api/). If an alternative framework (e.g., Next.js API routes) is used, implement /api/routes as a Next.js API route that inspects the filesystem under pages/api or app/api to list route filenames mapped to paths.

Date reference for generatedAt: use new Date().toISOString() at runtime.

This pull request was created as a result of the following prompt from Copilot chat.

Implement a new REST endpoint GET /api/routes in the repository Sushant0753/AI-Assistant.

Goal:
Provide a consolidated list of all public API endpoints served by the application so that clients (and future auto-documentation tooling) can discover capabilities programmatically.

Requirements:

  1. Create a new route handler mounted at /api/routes that returns JSON.
  2. Response shape:
    {
    "routes": [
    { "method": "GET", "path": "/api/routes" },
    { "method": "GET", "path": "/api/health" },
    ... other routes ...
    ],
    "generatedAt": "2025-11-17T15:10:10.000Z"
    }
  3. The list of routes should be generated automatically from the Express (or chosen framework) app/router configuration rather than hard-coded, if the project uses Express. If automatic introspection is not feasible with current framework, create a central route registration module that exports an array describing each route and reuse it both for registration and for /api/routes output.
  4. Add TypeScript types for the route descriptor: interface ApiRoute { method: string; path: string; description?: string }
  5. Ensure the endpoint is CORS-safe if the project already configures CORS (reuse existing middleware).
  6. Include basic tests:
    • Unit test verifying that GET /api/routes returns 200 and a non-empty routes array containing itself.
    • Test that each route object has method and path.
  7. Update any existing README or API documentation section to mention the new discovery endpoint.
  8. If there is no existing server entry point, create one (e.g., src/server.ts) using Express with an example additional route (e.g., /api/health) so /api/routes has at least two entries.
  9. Follow existing code style: prefer TypeScript, ES modules (or CommonJS) matching repository convention, and run any existing lint scripts.
  10. Do not break existing functionality; ensure build passes.

Implementation Outline (adjust to existing structure after inspecting repo):

  • Introduce a route registry module: src/api/routeRegistry.ts exporting an array of ApiRoute and a function to register routes to an Express Router.
  • /api/routes handler reads the registry and returns JSON with timestamp.
  • If Express app already exists, enhance it; otherwise scaffold minimal Express app with routes.
  • Add tests in a new test file (e.g., tests/routes.spec.ts) using chosen test framework (Jest assumed if present). If no test framework, add Jest config minimally.

Edge Cases / Notes:

  • Ensure duplicate route entries are filtered out.
  • Support future extension for descriptions and versioning.
  • Avoid including internal or non-API routes (like static file serving) unless they fall under /api/ prefix.

Deliverables:

  • New/updated TypeScript source files implementing /api/routes.
  • Tests passing locally.
  • README updated with example response.

Please inspect the repository to adapt file paths (e.g., src/, server/, api/). If an alternative framework (e.g., Next.js API routes) is used, implement /api/routes as a Next.js API route that inspects the filesystem under pages/api or app/api to list route filenames mapped to paths.

Date reference for generatedAt: use new Date().toISOString() at runtime.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel

vercel Bot commented Nov 17, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
ai-assistant Ready Ready Preview Comment Nov 17, 2025 3:11pm

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

Successfully merging this pull request may close these issues.

2 participants