{"id":13836094,"url":"https://github.com/fastify/fastify-accepts-serializer","last_synced_at":"2025-05-09T00:08:55.312Z","repository":{"id":23607860,"uuid":"99145869","full_name":"fastify/fastify-accepts-serializer","owner":"fastify","description":"Serializer according to the accept header","archived":false,"fork":false,"pushed_at":"2025-05-01T10:38:23.000Z","size":137,"stargazers_count":28,"open_issues_count":0,"forks_count":12,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-05-09T00:08:49.236Z","etag":null,"topics":["fastify","fastify-plugin"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@fastify/accepts-serializer","language":"JavaScript","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/fastify.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,"zenodo":null},"funding":{"github":"fastify","open_collective":"fastify"}},"created_at":"2017-08-02T17:53:56.000Z","updated_at":"2025-05-01T10:38:20.000Z","dependencies_parsed_at":"2023-01-13T23:34:01.125Z","dependency_job_id":"0c182eb8-d920-4a10-89c7-b429f10cccfe","html_url":"https://github.com/fastify/fastify-accepts-serializer","commit_stats":{"total_commits":140,"total_committers":24,"mean_commits":5.833333333333333,"dds":0.7357142857142858,"last_synced_commit":"a34cbee8dd97d1c28dc7e517449181c4b935a434"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-accepts-serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-accepts-serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-accepts-serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Ffastify-accepts-serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastify","download_url":"https://codeload.github.com/fastify/fastify-accepts-serializer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166521,"owners_count":21864482,"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":["fastify","fastify-plugin"],"created_at":"2024-08-04T15:00:35.426Z","updated_at":"2025-05-09T00:08:55.303Z","avatar_url":"https://github.com/fastify.png","language":"JavaScript","readme":"# @fastify/accepts-serializer\n\n[![CI](https://github.com/fastify/fastify-accepts-serializer/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify-accepts-serializer/actions/workflows/ci.yml)\n[![npm version](https://img.shields.io/npm/v/@fastify/accepts-serializer)](https://www.npmjs.com/package/@fastify/accepts-serializer)\n[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)\n\nSerialize according to the `Accept` header.\n\n\n## Install\n```sh\nnpm i @fastify/accepts-serializer\n```\n\n### Compatibility\n\n| Plugin version | Fastify version |\n| ---------------|-----------------|\n| `\u003e=6.x`        | `^5.x`          |\n| `^5.x`         | `^4.x`          |\n| `\u003e=3.x \u003c5.x`   | `^3.x`          |\n| `^2.x`         | `^2.x`          |\n| `^1.x`         | `^1.x`          |\n\n\nPlease note that if a Fastify version is out of support, then so are the corresponding versions of this plugin\nin the table above.\nSee [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.\n\n## Usage\n```js\n\nconst protobuf = require('protobufjs')\nconst YAML = require('yamljs')\nconst msgpack = require('msgpack5')()\n\nconst root = protobuf.loadSync('test/awesome.proto')\nconst AwesomeMessage = root.lookupType('awesomepackage.AwesomeMessage')\n\nconst fastify = require('fastify')()\n\n// Global serializers\nfastify.register(require('@fastify/accepts-serializer'), {\n  serializers: [\n    {\n      regex: /^application\\/yaml$/,\n      serializer: body =\u003e YAML.stringify(body)\n    },\n    {\n      regex: /^application\\/x-msgpack$/,\n      serializer: body =\u003e msgpack.encode(body)\n    }\n  ],\n  default: 'application/yaml' // MIME type used if Accept header does not match anything\n})\n\n// Per-router serializers\nconst config = {\n  serializers: [\n    {\n      regex: /^application\\/x-protobuf$/,\n      serializer: body =\u003e AwesomeMessage.encode(AwesomeMessage.create(body)).finish()\n    }\n  ]\n}\n\nfastify.get('/request', { config }, function (req, reply) {\n  reply.send({pippo: 'pluto'})\n})\n```\n\n## Behavior\n\nFor each route, a SerializerManager is defined, which has both per-route and global serializer definitions.\n\nThe MIME type `application/json` is always handled by `fastify` if no serializer is registered for that MIME type.\n\nIf no `default` key is specified in configuration, all requests with an unknown `Accept` header will be replied to with a 406 response (a boom error is used).\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","funding_links":["https://github.com/sponsors/fastify","https://opencollective.com/fastify"],"categories":["\u003ch2 align=\"center\"\u003eAwesome Fastify\u003c/h2\u003e"],"sub_categories":["\u003ch2 align=\"center\"\u003eEcosystem\u003c/h2\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Ffastify-accepts-serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastify%2Ffastify-accepts-serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Ffastify-accepts-serializer/lists"}