hetter
v1.1.1
Published
A router handler
Downloads
1
Readme
hetter
A simple route manager for Next.js API Routes.
Installation
with npm:
$ npm i hetter
with yarn:
$ yarn add hetter
Usage
In this example we will create user
api routes
Folder structure
pages
┣ api
┃ ┣ user
┃ ┃ ┗ UserController.ts
┃ ┗ [[...path]].ts
┗ index.tsx
Handling
On [[...path]].ts
file:
import { NextApiRequest, NextApiResponse } from 'next'
import Hetter from 'hetter'
import UserController from './user/UserController'
export default function handler(req: NextApiRequest, res: NextApiResponse) {
const Route = new Hetter(req, res)
Route.get('/users/:id', UserController.index)
Route.post('/users/:id', UserController.store)
}