# nestjs-json-api-serializer

> Nestjs serializer to use with jsonapi.org pattern

Latest version **0.0.0** (published 2022-07-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install nestjs-json-api-serializer
pnpm add nestjs-json-api-serializer
yarn add nestjs-json-api-serializer
bun add nestjs-json-api-serializer
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2022-07-01 |
| First published | 2022-07-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Cassino |
| Maintainers | tacnoman |
| Keywords | nest, serializer, jsonapi, json, api |

## Links

- npm: https://www.npmjs.com/package/nestjs-json-api-serializer
- Repository: https://github.com/renatocassino/json-api-serializer
- Homepage: https://github.com/renatocassino/json-api-serializer#readme
- Issues: https://github.com/renatocassino/json-api-serializer/issues
- npm.io page: https://npm.io/package/nestjs-json-api-serializer

## Dependencies (3)

- [rxjs](https://npm.io/package/rxjs.md) ^7.5.5
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^6.0.5
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.0 (latest) — 2022-07-01

## README

<p align="center">
  <a href="http://nestjs.com/" target="blank">
    <img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" />
  </a>
</p>

<p align="center">
  A lib to NestJS to serializer JSON following the <a href="https://jsonapi.org/">JSON Api</a> pattern.
</p>

## Installation

Run in your terminal

```bash
$ npm install --save @nestjs-modules/json-api-serializer
```

or via yarn

```bash
$ yarn add @nestjs-modules/json-api-serializer
```

## Getting started

```ts
import {
  Controller,
  Get,
  UseInterceptors,
} from '@nestjs/common';
import { JsonApiInterceptor } from '@nestjs-modules/json-api-serializer';

@Controller('v1/cats')
export class CatsController {
  
  @UseInterceptors(JsonApiInterceptor)
  @Get()
  async index() {
    return {
      data: [ /* my array of objects */ ],
    };
  }
}
```

When you make a curl to `http://localhost/v1/cats` the `JsonApiInterceptor` will change your payload following the JSON Api pattern.

```json
{
  "data": [
    {
      "id": 2,
      "attributes": {
        "color": "orange",
        "name": "Shadow",
        "genre": "male"
      },
      "relations": {
        "power": {
          "id": 33,
          "attributes": {
            "powerName": "meow"
          }
        }
      }
    },
    {
      "id": 12,
      "attributes": {
        "color": "brown",
        "name": "british",
        "genre": "female"
      },
      "relations": {
        "power": {
          "id": 34,
          "attributes": {
            "powerName": "purr"
          }
        }
      }
    }
  ]
}
```

### Fields

Following the [JSON Api fields pattern](https://jsonapi.org/format/#document-resource-object-fields), if you pass a queryString called `fields` you can get only fields listed.

Example: `http://localhost:3000/v1/cats?fields=color,name` the result should be:

```json
{
  "data": [
    {
      "id": 2,
      "attributes": {
        "color": "orange",
        "name": "Shadow"
      }
    },
    {
      "id": 12,
      "attributes": {
        "color": "brown",
        "name": "british"
      }
    }
  ]
}
```

---
_Source: https://npm.io/package/nestjs-json-api-serializer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
