Skip to content

Count REST endpoints by framework-specific patterns #9

@mvoutov

Description

@mvoutov

What

Count REST API endpoints by grepping for framework-specific route patterns. Report the count and HTTP methods in the scan output.

Why

Knowing "Express app with 14 GET, 8 POST, 3 PUT, 2 DELETE endpoints" tells Claude (and the developer) the shape of the API surface without reading every file.

How

Edit src/lib/scanner.js. Add a countRESTEndpoints(repoPath, frameworks) function that runs framework-specific grep patterns.

Patterns by framework

Express / Fastify / Hono (JS/TS):

app.get(     router.get(     .get(
app.post(    router.post(    .post(
app.put(     router.put(     .put(
app.delete(  router.delete(  .delete(
app.patch(   router.patch(   .patch(

Regex: /\.(get|post|put|delete|patch)\s*\(/g
Search in: all .js/.ts files under src/, routes/, api/, server/

FastAPI (Python):

@app.get(    @router.get(
@app.post(   @router.post(

Regex: /@(?:app|router)\.(get|post|put|delete|patch)\s*\(/g
Search in: all .py files

Flask (Python):

@app.route(    @blueprint.route(

Regex: /@(?:app|blueprint|\w+)\.route\s*\(/g
Search in: all .py files

Django REST Framework (Python):
Look for ViewSet classes and @api_view decorators.
Regex: /class\s+\w+ViewSet|@api_view/g

Spring Boot (Java/Kotlin):

@GetMapping    @PostMapping    @PutMapping
@DeleteMapping @PatchMapping   @RequestMapping

Regex: /@(Get|Post|Put|Delete|Patch|Request)Mapping/g
Search in: all .java/.kt files

Implementation

function countRESTEndpoints(repoPath, frameworks) {
  const counts = { get: 0, post: 0, put: 0, delete: 0, patch: 0, total: 0 };

  // Determine which patterns to use based on detected frameworks
  const expressLike = ['express', 'fastify', 'hono'].some(f => frameworks.includes(f));
  const fastapi = frameworks.includes('fastapi');
  const flask = frameworks.includes('flask');
  const django = frameworks.includes('django');

  // Walk source files and grep for patterns
  // Use the existing walkSourceFiles or a simpler targeted walk
  // For each match, increment the appropriate method counter

  counts.total = counts.get + counts.post + counts.put + counts.delete + counts.patch;
  return counts.total > 0 ? counts : null;
}

Important: Don't read every file in the repo. Only scan files in directories likely to contain routes:

  • JS/TS: src/, routes/, api/, server/, app/api/ (Next.js)
  • Python: app/, api/, src/, files matching *route*, *view*, *endpoint*
  • Java: src/main/java/ recursively

Display

In src/commands/scan.js:

  API endpoints: 27 total (14 GET, 8 POST, 3 PUT, 2 DELETE)

Files to change

  • src/lib/scanner.js — add countRESTEndpoints(), call from scanRepo()
  • src/commands/scan.js — display endpoint counts
  • tests/scanner.test.js — add tests with fixture files containing route patterns

Acceptance criteria

  • npm test passes
  • Counts Express-style routes correctly (.get(, .post(, etc.)
  • Counts FastAPI/Flask decorators correctly
  • Only scans relevant directories (not the whole repo)
  • aspens scan shows endpoint breakdown when routes are found

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions