Skip to content

Adamya-Gupta/Apifinder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apifinder

MIT License npm version

Automatically discover and document Next.js API endpoints by analyzing your project's file structure. Apifinder scans your Next.js project for API routes in both Pages Router and App Router patterns, extracts HTTP methods, and generates clean, human-readable documentation.

Purpose of creating this package

I personally enjoy documenting my own projects. But every time I had to create API documentation, I found myself repeating the same tedious process: manually going through each file, identifying endpoints, figuring out the HTTP methods, and formatting everything nicely.

Eventually, I started procrastinating on documenting older projects because revisiting my own code just to extract API routes felt time-consuming and mentally exhausting.

That’s when I decided to build Apifinder — a small utility to automate this process for myself. It turned out to be incredibly helpful, and I realized others might face the same challenge. So, I made it public, hoping it can save time and effort for anyone looking to auto-generate clean API documentation from their Next.js project.

Features

  • 🔍 Automatically detects API routes (Pages & App Router)
  • ⚡ CLI and programmatic usage support
  • 📝 Generates and updates README.md or custom documentation files
  • 📦 Outputs Markdown or JSON
  • 📁 Supports monorepos and custom src/ structures

Installation

# Install npm package in your project repo
npm i @adamtools/apifinder

CLI Usage (Recommended)

# Analyze current directory and update README.md
apifinder

# Analyze specific project path
apifinder --path /path/to/your/nextjs-project

# Output to custom file
apifinder --output API_DOCS.md

# Preview without updating files
apifinder --dry-run

# Get JSON output
apifinder --json

Tip

You can also try with npx:

npx apifinder

Programmatic Usage

const { ApiFinder } = require('apifinder');

async function analyzeProject() {
  const analyzer = new ApiFinder('./my-nextjs-project');
  const endpoints = await analyzer.analyze();
  
  console.log('Found endpoints:', endpoints);
  
  // Generate markdown table
  const markdownTable = analyzer.generateMarkdownTable();
  console.log(markdownTable);
  
  // Update README.md
  await analyzer.updateReadme();
}

analyzeProject();

Supported Patterns

Pages Router

  • pages/api/users.js → /api/users
  • pages/api/users/[id].js → /api/users/:id
  • pages/api/posts/[...slug].js → /api/posts/*slug
  • src/pages/api/auth/login.js → /api/auth/login

App Router

  • app/api/users/route.js → /api/users
  • app/api/users/[id]/route.js → /api/users/:id
  • app/api/posts/[...slug]/route.js → /api/posts/*slug
  • src/app/api/auth/login/route.js → /api/auth/login

Output Example

ApiFinder generates a table like this in your README:

Route Methods File Type
/api/auth/login POST pages/api/auth/login.js Pages Router
/api/users GET, POST app/api/users/route.js App Router
/api/users/:id GET, PUT, DELETE app/api/users/[id]/route.js App Router
/api/posts/*slug GET pages/api/posts/[...slug].js Pages Router

Configuration

CLI Options

Option Description Default
-p, --path <path> Path to Next.js project Current directory
-o, --output <file> Output README file README.md
--dry-run Show endpoints without updating README false
--json Output endpoints as JSON false

About

FInds all api endpoints of any nextjs project and adds them into readme.md , makes the documentation easier

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published