santigp258 / homebrew-apext

A simple CLI tool to manage your Next.js API routes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

apextgithub

APEXT

pronounced /eɪpekst/

A simple CLI tool to output all your Next.js API routes in your console.

Inspired by the Laravel Artisan route:list Command

⚠️ For now it is macOS only ⚠️

Install

brew install lifespikes/apext/apext

API (Commands)

🎯 list

Place yourself on your Next.js root directory and run apext list

Flags:

--path - optional (will output a specific path routes, /api is default)

Example:

apext list --path=auth

🎯 create

Will create an API endpoint following a REST structure.

Flags:

--name - required (the name of your API endpoint)

--path - optional (/api folder is default)

--ts - optional (.js file is generated by default)

Example:

apext create --name=login --path=auth --ts

Notes:

  1. When stating a --path you can create nested directories like organization/public.
  2. If a folder does not exists, APEXT will create the folder for you.

Output file (typescript):

import type { NextApiRequest, NextApiResponse } from 'next'

export default async function name(
  req: NextApiRequest,
  res: NextApiResponse
) {
  switch (req.method) {
    case 'GET':
    case 'POST':
    case 'PUT':    
    case 'DELETE':
    default:
      res.setHeader('Allow', [
        'GET',
        'POST',
        'PUT',
        'DELETE',
    ])
      return res.status(405).end(`Method ${req.method} Not Allowed`)
  }
}

output

About

A simple CLI tool to manage your Next.js API routes.

License:MIT License


Languages

Language:TypeScript 83.2%Language:JavaScript 11.6%Language:Ruby 5.2%