{"id":15729392,"url":"https://github.com/zaida04/nextjs-api-decorators","last_synced_at":"2025-03-31T02:31:12.771Z","repository":{"id":130193524,"uuid":"498940012","full_name":"zaida04/nextjs-api-decorators","owner":"zaida04","description":"✨ Create your Next.JS API using TypeScript decorators","archived":false,"fork":false,"pushed_at":"2022-06-02T02:44:39.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T07:32:38.482Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/zaida04.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","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-06-02T00:31:46.000Z","updated_at":"2025-02-04T01:56:43.000Z","dependencies_parsed_at":"2023-06-06T00:00:44.335Z","dependency_job_id":null,"html_url":"https://github.com/zaida04/nextjs-api-decorators","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaida04%2Fnextjs-api-decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaida04%2Fnextjs-api-decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaida04%2Fnextjs-api-decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaida04%2Fnextjs-api-decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zaida04","download_url":"https://codeload.github.com/zaida04/nextjs-api-decorators/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246406550,"owners_count":20771967,"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":"2024-10-03T23:21:24.727Z","updated_at":"2025-03-31T02:31:12.589Z","avatar_url":"https://github.com/zaida04.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `nextjs-api-decorators`\n\n[![GitHub](https://img.shields.io/github/license/zaida04/nextjs-api-decorators)](https://github.com/zaida04/nextjs-api-decorators/blob/main/LICENSE)\n[![npm](https://img.shields.io/npm/v/nextjs-api-decorators?color=crimson\u0026logo=npm)](https://www.npmjs.com/package/nextjs-api-decorators)\n[![CI workflows](https://github.com/zaida04/nextjs-api-decorators/actions/workflows/ci.yml/badge.svg)](https://github.com/zaida04/nextjs-api-decorators/actions/workflows/ci.yml)\n\n## ❓ About\n\nThis package is an addon to next.js that allows you to use decorators in a class setting to structure your Next.JS API. This was created due to the age old problem in Next.JS of having to do\n\n```typescript\nexport default APIHandlingFunction(req, res) {\n  if(req.method === \"GET\") {\n    ...\n  } else if (req.method === \"POST\") {\n    ...\n  }\n}\n```\n\nin every API file. This leads to clutter, or you having to duplicate a fix using the map solution implemented in this library across all your files.\n\n## 📥 Installation\n\nYou can install this package from [NPM](https://www.npmjs.com/package/nextjs-api-decorators)\n\n-   `npm install nextjs-api-decorators`\n-   `yarn add nextjs-api-decorators`\n\n## ⚡ Usage\n\nDemo file based on a template project generated with next-create-app  \n`pages/api/items/[itemId].tsx`\n\n```typescript\nimport { NextApiRequest, NextApiResponse } from \"next\";\nimport { http, genAPIRoute } from \"nextjs-api-decorators\";\n\n// You can name the class whatever you want, doesn't matter. It's only there for us to be able to use decorators\nclass ItemRoutes {\n    @http(\"ItemRoutes\")\n    GET(req: NextApiRequest, res: NextApiResponse) {\n        return res.status(200).json({ success: true });\n    }\n}\n\nexport default genAPIRoute(\"ItemRoutes\");\n```\n\n## ✋ Contributing\n\nContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\nPlease ensure any and all commits pass our linting and build steps as described in the root package.json.\n\n## ⚖️ LICENSE\n\nLicensed under the [MIT License](https://github.com/zaida04/nextjs-api-decorators/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaida04%2Fnextjs-api-decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzaida04%2Fnextjs-api-decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaida04%2Fnextjs-api-decorators/lists"}