{"id":15539176,"url":"https://github.com/tzellman/nest-jsonapi","last_synced_at":"2025-04-15T01:43:52.534Z","repository":{"id":43695513,"uuid":"330687028","full_name":"tzellman/nest-jsonapi","owner":"tzellman","description":"A nestjs module that provides JSONAPI support to your application.","archived":false,"fork":false,"pushed_at":"2025-04-12T13:29:01.000Z","size":1472,"stargazers_count":17,"open_issues_count":12,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T14:39:41.377Z","etag":null,"topics":["hacktoberfest","jsonapi","nest","nestjs","typescript"],"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/tzellman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2021-01-18T14:12:34.000Z","updated_at":"2025-04-05T16:08:36.000Z","dependencies_parsed_at":"2023-01-21T17:03:04.194Z","dependency_job_id":"a63dc3e5-a0bf-4401-a28d-adc4dc81d635","html_url":"https://github.com/tzellman/nest-jsonapi","commit_stats":{"total_commits":111,"total_committers":2,"mean_commits":55.5,"dds":"0.26126126126126126","last_synced_commit":"5d40d5281744306ebd8285b4c51b8ffb57ddeb8f"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tzellman%2Fnest-jsonapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tzellman%2Fnest-jsonapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tzellman%2Fnest-jsonapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tzellman%2Fnest-jsonapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tzellman","download_url":"https://codeload.github.com/tzellman/nest-jsonapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991526,"owners_count":21194893,"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":["hacktoberfest","jsonapi","nest","nestjs","typescript"],"created_at":"2024-10-02T12:09:31.792Z","updated_at":"2025-04-15T01:43:52.517Z","avatar_url":"https://github.com/tzellman.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM][npm-badge-img]][npm-badge-link]\n[![Build Status][build-status-img]][build-status-link]\n[![Download count][npm-downloads-img]][npm-badge-link]\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com\"\u003e\u003cimg src=\"https://nestjs.com/img/logo_text.svg\" alt=\"Nest Logo\" width=\"320\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  A \u003ca href=\"https://github.com/nestjs/nest\"\u003eNest\u003c/a\u003e module that provides \u003ca href=\"https://jsonapi.org/\"\u003eJSONAPI\u003c/a\u003e integration.\n\u003c/p\u003e\n\n## Installation\n\n```bash\nnpm install --save nest-jsonapi\n```\n\n## Usage\n\nImport the `JsonapiModule` into the root `AppModule` and use the `forRoot()` method to configure it:\n\n```typescript\nimport { JsonapiModule } from \"nest-jsonapi\";\n\n@Module({\n    imports: [\n        JsonapiModule.forRoot({\n            // options\n        }),\n    ],\n})\nexport class AppModule {}\n```\n\nInject `JsonapiService`:\n\n```typescript\nimport { JsonapiService, JSONAPI_MODULE_SERVICE } from \"nest-jsonapi\";\n\n@Controller(\"photos\")\nexport class PhotosController {\n    constructor(@Inject(JSONAPI_MODULE_SERVICE) private readonly jsonapiService: JsonapiService) {}\n}\n```\n\nNote that `JsonapiModule` is a global module, therefore it will be available in all modules.\n\n### Middleware\n\nIf you plan on using the `JsonapiPayload` decorator (more info below), you must use the `JsonapiMiddleware` in your application. This does 2 things:\n\n1. enable parsing jsonapi content as JSON\n2. creates a request-scoped holder for tracking metadata\n\ne.g.\n\n```typescript\nexport class AppModule implements NestModule {\n    public configure(consumer: MiddlewareConsumer): void {\n        consumer.apply(JsonapiMiddleware).forRoutes(PhotosController);\n    }\n}\n```\n\n### Interceptor\n\nThe `JsonapiInterceptor` is used to properly transform your controller result data to JSONAPI. You can decorate at a class or method level:\n\n```typescript\n@UseInterceptors(JsonapiInterceptor)\n@Controller(\"photos\")\nexport default class PhotosController {}\n```\n\n### Payload Metadata\n\nIn order for the `JsonapiInterceptor` to know _how_ to transform your data, you need to decorate your methods.\n\n```typescript\n@JsonapiPayload({ resource: RESOURCE_PHOTOS })\n@Get()\npublic async findPhotos(@Query() query: FindOptions): Promise\u003cPhoto[]\u003e\n```\n\n### Exception Filter\n\nIn order to support error responses compliant with the JSONAPI specification, the `JsonapiExceptionFilter` exists.\n\n```typescript\nconst { httpAdapter } = app.get(HttpAdapterHost);\napp.useGlobalFilters(new JsonapiExceptionFilter(httpAdapter));\n```\n\n### Schema Registration\n\nThe `JsonapiService` requires schemas for the resources it is going to handle. You have control of how that is configured, by defining a schematic. We provide a thin wrapper around the `transformalizer` library.\n\nTypically you will want to register your schemas on module initialization.\n\n```typescript\nexport class AppModule implements OnModuleInit {\n    constructor(@Inject(JSONAPI_MODULE_SERVICE) private readonly jsonapiService: JsonapiService) {}\n\n    public async onModuleInit(): Promise\u003cvoid\u003e {\n        const photoBuilder = new SchemaBuilder\u003cPhoto\u003e(RESOURCE_PHOTOS);\n        photoBuilder.dataBuilder.untransformAttributes({ deny: [\"createdAt\", \"updatedAt\"] });\n        this.jsonapiService.register(photoBuilder);\n    }\n}\n```\n\n## Reference Example\n\n[nest-jsonapi-example](https://github.com/tzellman/nest-jsonapi-example) is an example project that demonstrates the usage of this module. Since not all aspects of the module have been fully tested yet (coming soon!), I highly suggest checking this out!\n\n## API Docs\n\nFor detailed API information please visit the [API documentation](https://tzellman.github.io/nest-jsonapi/index.html).\n\n## Contributing\n\nSee the [Contributing](CONTRIBUTING.md) guide for details.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE.md).\n\n[npm-badge-img]: https://badge.fury.io/js/nest-jsonapi.svg\n[npm-badge-link]: http://badge.fury.io/js/nest-jsonapi\n[build-status-img]: https://github.com/tzellman/nest-jsonapi/workflows/Node.js%20CI/badge.svg?branch=master\u0026event=push\n[build-status-link]: https://github.com/tzellman/nest-jsonapi/actions/workflows/node.js.yml\n[npm-downloads-img]: https://img.shields.io/npm/dt/nest-jsonapi.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftzellman%2Fnest-jsonapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftzellman%2Fnest-jsonapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftzellman%2Fnest-jsonapi/lists"}