next-api-controller
v0.1.4
Published
Next.js controller and controller handler function to help create cleaner RESTful API endpoints
Downloads
7
Maintainers
Readme
next-api-controller
A simple Next.js controller handler function to help create cleaner RESTful API endpoints.
Installation
# npm
npm install next-api-controller
# yarn
yarn add next-api-controller
Typescript Usage
// controllers/exampleController.ts
import { Controller } from "next-api-controller";
const exampleController: Controller {
get: (req,res) => {
res.status(200).json({ message: "Hello World!" });
}
}
export default exampleController;
// pages/api/example.ts
import { createHandler } from "next-api-controller";
import exampleController from "../../controllers/exampleController";
return createHandler(exampleController);