{"id":24511711,"url":"https://github.com/devnax/nextjs-super-api","last_synced_at":"2025-03-15T09:44:22.890Z","repository":{"id":112973504,"uuid":"450789605","full_name":"devnax/nextjs-super-api","owner":"devnax","description":null,"archived":false,"fork":false,"pushed_at":"2022-07-19T13:56:13.000Z","size":370,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T08:37:44.016Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devnax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-22T10:50:59.000Z","updated_at":"2025-02-09T09:21:53.000Z","dependencies_parsed_at":"2023-08-15T05:15:57.245Z","dependency_job_id":null,"html_url":"https://github.com/devnax/nextjs-super-api","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"b276ae99b2dc94c5b35205f8f92558d00f3d5ad5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fnextjs-super-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fnextjs-super-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fnextjs-super-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devnax%2Fnextjs-super-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devnax","download_url":"https://codeload.github.com/devnax/nextjs-super-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243713388,"owners_count":20335566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-22T00:40:46.898Z","updated_at":"2025-03-15T09:44:22.866Z","avatar_url":"https://github.com/devnax.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e Basic and Simple Routing system for nextjs\n\n\n## Configure\n```js\n// next.config.js\nmodule.exports = {\n  async rewrites() {\n    return [\n      {\n        source: '/api/v1/:base/:path*',\n        destination: '/api/v1/:base*'\n      }\n    ]\n  }\n}\n\n```\n\n\n\n## Uses\n```js\n// api/v1/users.js\n\nimport Router from 'nextjs-super-api'\n\nclass UserRoutes extends Router{\n  basepath = '/v1/users' // optional\n\n  constructor(){\n    super()\n    this.post('/', this.createUser)\n    this.get('/', this.getUsers)\n    \n    this.put(...)\n    this.delete(...)\n    this.connect(...)\n    this.option(...)\n    this.trace(...)\n    this.patch(...)\n\n    // Middleware\n    this.use(this.middleware, (req, res) =\u003e {}, () =\u003e {})\n\n    // With Path\n    this.use('/', this.middleware, () =\u003e {}, () =\u003e {})\n\n\n    // you can use also\n    this.get(path, ...middlewares, () =\u003e {}, this.another, ...)\n\n\n    // params\n    this.get('/:user_id', this.getUser)\n\n    // another example\n    this.get('/:post_category/:post_id', this.getPosts)\n\n  }\n\n  middleware(req, res, next){\n    next()\n    // or you can call this.next()\n  }\n\n  async catchError(err){\n    this.error(err.message)\n  }\n\n  async createUser(req, res){\n    const {firstname, lastname, email, password} = this.data\n    const create = '...'\n\n    if(create){\n      this.json({message: \"User Created\"}, 200); // default 200\n    }else{\n      this.error(\"Something wrong\") // or you can catch all  error from this.catchError method\n    }\n  }\n\n  async getUsers(){\n    // ....\n    const user = \"\"\n\n    this.json(user)\n  }\n\n}\n\n\n\nexport default UserRoute.listen() // Must call this\n\n\n// Methods you can call in class\n\nthis.next() // this is for middleare\nthis.body // req.body\nthis.params // req.params\nthis.query // req.query\nthis.headers // req.headers\nthis.json(object, code?)\nthis.error(string|object, code?)\nthis.status(200, string|object)\n```\n\n\n\n## Typescript\n\n```ts\nimport Router, {RouterType} from 'nextjs-super-api'\n\ninterface MyType extends RouterType{\n  routes: {\n    get: \"/\" | \"/:id\",\n    post: \"/\"\n  },\n  response: string | object;\n  statusCodes: {\n    200: \"Success\"\n  },\n  query: {[key: string]: string | string[]};\n  params: {[key: string]: string | string[]};\n  body: any;\n}\n\n\nclass UserRoutes extends Router\u003cMyType\u003e{\n\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevnax%2Fnextjs-super-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevnax%2Fnextjs-super-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevnax%2Fnextjs-super-api/lists"}