Apext Logo

APEXT

Create Command

This command will create an API route with a generic REST structure within the api folder. A <name> is required and will be used to create the route.

apext create <name>

Options:

  • --path (optional): The path to the API route. If the path does not exist, it will be created. Default: /pages/api/<name>.
apext create login --path auth
  • --ts (optional): Creates a Typescript file instead a Javascript file.
apext create login --ts

File Structure

The file will be created in the api folder with the following structure:

export default async function name(req,res) {

// @methods [GET,POST,PUT,DELETE]

switch (req.method) {
    case 'GET':
        // GET REQUEST
    case 'POST':
        // POST REQUEST
    case 'PUT':
        // PUT REQUEST
    case 'DELETE':
        // DELETE REQUEST
    default:
    res.setHeader('Allow', [
        'GET',
        'POST',
        'PUT',
        'DELETE',
    ])
    return res.status(405).end(\`Method \${req.method} Not Allowed\`)
    }
}

Advanced Options:

You can specify the content of the file on the Config File. This option will override the default content of the file.

An open source project powered by LifeSpikes

MIT Licensed - 2022