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
brew install lifespikes/apext/apext
Place yourself on your Next.js root directory and run apext list
--path
- optional (will output a specific path routes, /api
is default)
apext list --path=auth
Will create an API endpoint following a REST structure.
--name
- required (the name of your API endpoint)
--path
- optional (/api
folder is default)
--ts
- optional (.js
file is generated by default)
apext create --name=login --path=auth --ts
- When stating a
--path
you can create nested directories likeorganization/public
. - If a folder does not exists, APEXT will create the folder for you.
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`)
}
}