Installations
npm install @fastify/accepts-serializer
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
20.18.0
NPM Version
10.8.2
Score
76
Supply Chain
94
Quality
88.3
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Languages
JavaScript (94.52%)
TypeScript (5.48%)
Developer
Download Statistics
Total Downloads
67,948
Last Day
323
Last Week
1,480
Last Month
5,323
Last Year
36,265
GitHub Statistics
28 Stars
169 Commits
12 Forks
17 Watching
4 Branches
27 Contributors
Bundle Size
155.83 kB
Minified
24.52 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
6.0.2
Package Id
@fastify/accepts-serializer@6.0.2
Unpacked Size
23.72 kB
Size
5.60 kB
File Count
14
NPM Version
10.8.2
Node Version
20.18.0
Publised On
14 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
67,948
Last day
1.3%
323
Compared to previous day
Last week
3.9%
1,480
Compared to previous week
Last month
13.1%
5,323
Compared to previous month
Last year
84.5%
36,265
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Dev Dependencies
8
@fastify/accepts-serializer
Serialize according to the Accept
header.
Install
1npm i @fastify/accepts-serializer
Compatibility
Plugin version | Fastify version |
---|---|
^6.x | ^5.x |
^5.x | ^4.x |
^3.x | ^3.x |
^2.x | ^2.x |
^1.x | ^1.x |
Please note that if a Fastify version is out of support, then so are the corresponding version(s) of this plugin in the table above. See Fastify's LTS policy for more details.
Usage
1 2const protobuf = require('protobufjs') 3const YAML = require('yamljs') 4const msgpack = require('msgpack5')() 5 6const root = protobuf.loadSync('test/awesome.proto') 7const AwesomeMessage = root.lookupType('awesomepackage.AwesomeMessage') 8 9const fastify = require('fastify')() 10 11// Global serializers 12fastify.register(require('@fastify/accepts-serializer'), { 13 serializers: [ 14 { 15 regex: /^application\/yaml$/, 16 serializer: body => YAML.stringify(body) 17 }, 18 { 19 regex: /^application\/x-msgpack$/, 20 serializer: body => msgpack.encode(body) 21 } 22 ], 23 default: 'application/yaml' // MIME type used if Accept header don't match anything 24}) 25 26// Per-router serializers 27const config = { 28 serializers: [ 29 { 30 regex: /^application\/x-protobuf$/, 31 serializer: body => AwesomeMessage.encode(AwesomeMessage.create(body)).finish() 32 } 33 ] 34} 35 36fastify.get('/request', { config }, function (req, reply) { 37 reply.send({pippo: 'pluto'}) 38})
Behaviour
For each route, a SerializerManager is defined, which has both per-route and global serializer definitions.
The MIME type application/json
is always handled by fastify
if no serializer is registered for that MIME type.
If 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).
License
Licensed under MIT.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
18 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/fastify/.github/SECURITY.md:1
- Info: Found linked content: github.com/fastify/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/fastify/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/fastify/.github/SECURITY.md:1
Reason
SAST tool is not run on all commits -- score normalized to 9
Details
- Warn: 18 commits out of 19 are checked with a SAST tool
Reason
Found 4/25 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
6.7
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More