import { Controller, API_Response, IControlFunction } from "./path/to/controller" import { NextApiRequest, NextApiResponse } from "next" // these controllers can be at different source file too const get_handler:IControlFunction = async (req,res) => { // do some stuff... res.json({ ok: true, data: { message: "@sfx_one" } }) } const post_handler: IControlFunction = async (req,res) => { // process some stuff... res.json({ ok: true, data: { subscriber_id: "@sfx_one" } }) } const api_handler = async (req: NextApiRequest,res: NextApiResponse) => { const controller = new Controller(req,res) // must set controls first controller.setControls({ GET: get_handler, POST: post_handler }) // do more stuff here... // call exec // exec returns a promise, make sure to 'await' it. await controller.exec() } export default api_handler