fastify 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/Ecosystem.md +6 -1
- package/docs/Hooks.md +0 -5
- package/docs/Recommendations.md +17 -0
- package/docs/Reply.md +2 -2
- package/docs/Request.md +1 -1
- package/docs/Routes.md +19 -1
- package/docs/Server.md +2 -0
- package/docs/Style-Guide.md +180 -0
- package/docs/TypeScript.md +359 -359
- package/examples/parser.js +1 -1
- package/fastify.js +8 -8
- package/lib/contentTypeParser.js +12 -11
- package/lib/context.js +4 -3
- package/lib/decorate.js +1 -1
- package/lib/fourOhFour.js +4 -4
- package/lib/handleRequest.js +5 -5
- package/lib/hooks.js +4 -4
- package/lib/logger.js +6 -6
- package/lib/pluginUtils.js +1 -1
- package/lib/reply.js +24 -21
- package/lib/reqIdGenFactory.js +2 -2
- package/lib/request.js +8 -5
- package/lib/route.js +9 -8
- package/lib/schemas.js +1 -1
- package/lib/server.js +5 -5
- package/lib/validation.js +8 -8
- package/package.json +8 -8
- package/test/404s.test.js +15 -15
- package/test/async-await.test.js +7 -7
- package/test/custom-parser-async.test.js +2 -2
- package/test/custom-parser.test.js +8 -8
- package/test/helper.js +1 -1
- package/test/hooks.test.js +6 -6
- package/test/http2/head.test.js +1 -1
- package/test/http2/plain.test.js +1 -1
- package/test/http2/secure-with-fallback.test.js +1 -1
- package/test/http2/secure.test.js +1 -1
- package/test/http2/unknown-http-method.test.js +1 -1
- package/test/https/https.test.js +2 -1
- package/test/inject.test.js +2 -2
- package/test/internals/all.test.js +1 -1
- package/test/internals/hookRunner.test.js +1 -1
- package/test/internals/logger.test.js +1 -1
- package/test/internals/reply.test.js +62 -7
- package/test/internals/request.test.js +23 -0
- package/test/listen.test.js +12 -0
- package/test/logger.test.js +10 -10
- package/test/nullable-validation.test.js +108 -0
- package/test/pretty-print.test.js +9 -14
- package/test/reply-error.test.js +2 -2
- package/test/route-hooks.test.js +10 -10
- package/test/stream.test.js +11 -11
- package/test/types/fastify.test-d.ts +1 -2
- package/test/types/logger.test-d.ts +1 -1
- package/test/types/route.test-d.ts +5 -0
- package/test/versioned-routes.test.js +55 -0
- package/types/.eslintrc.json +4 -1
- package/types/content-type-parser.d.ts +0 -15
- package/types/hooks.d.ts +138 -16
- package/types/instance.d.ts +81 -2
- package/types/logger.d.ts +1 -1
- package/types/plugin.d.ts +5 -7
- package/types/register.d.ts +8 -8
- package/types/route.d.ts +38 -58
- package/types/schema.d.ts +4 -4
- package/types/serverFactory.d.ts +9 -9
package/docs/Ecosystem.md
CHANGED
|
@@ -62,6 +62,8 @@ Plugins maintained by the fastify team are listed under [Core](#core) while plug
|
|
|
62
62
|
- [`fastify-blipp`](https://github.com/PavelPolyakov/fastify-blipp) Prints your routes to the console, so you definitely know which endpoints are available.
|
|
63
63
|
- [`fastify-bookshelf`](https://github.com/butlerx/fastify-bookshelfjs) Fastify plugin to add [bookshelf.js](http://bookshelfjs.org/) orm support.
|
|
64
64
|
- [`fastify-boom`](https://github.com/jeromemacias/fastify-boom) Fastify plugin to add [boom](https://github.com/hapijs/boom) support.
|
|
65
|
+
- [`fastify-casbin`](https://github.com/nearform/fastify-casbin) Casbin support for Fastify.
|
|
66
|
+
- [`fastify-casbin-rest`](https://github.com/nearform/fastify-casbin-rest) Casbin support for Fastify based on a RESTful model.
|
|
65
67
|
- [`fastify-casl`](https://github.com/Inlecom/fastify-casl) Fastify [CASL](https://github.com/stalniy/casl) plugin that supports ACL-like protection of endpoints via either a preSerialization & preHandler hook, sanitizing the inputs and outputs of your application based on user rights.
|
|
66
68
|
- [`fastify-cloudevents`](https://github.com/smartiniOnGitHub/fastify-cloudevents) Fastify plugin to generate and forward Fastify events in the Cloudevents format.
|
|
67
69
|
- [`fastify-cockroachdb`](https://github.com/alex-ppg/fastify-cockroachdb) Fastify plugin to connect to a CockroachDB PostgreSQL instance via the Sequelize ORM.
|
|
@@ -82,7 +84,6 @@ Plugins maintained by the fastify team are listed under [Core](#core) while plug
|
|
|
82
84
|
- [`fastify-google-cloud-storage`](https://github.com/carlozamagni/fastify-google-cloud-storage) Fastify plugin that exposes a GCP Cloud Storage client instance.
|
|
83
85
|
- [`fastify-grant`](https://github.com/simov/fastify-grant) Authentication/Authorization plugin for Fastify that supports 200+ OAuth Providers.
|
|
84
86
|
- [`fastify-guard`](https://github.com/hsynlms/fastify-guard) A fastify plugin that protects endpoints by checking authenticated user roles and/or scopes.
|
|
85
|
-
- [`fastify-gql`](https://github.com/mcollina/fastify-gql) A GraphQL server implementation for Fastify with caching and [`graphql-jit`](https://github.com/ruiaraujo/graphql-jit).
|
|
86
87
|
- [`fastify-graceful-shutdown`](https://github.com/hemerajs/fastify-graceful-shutdown) Shutdown Fastify gracefully and asynchronously.
|
|
87
88
|
- [`fastify-healthcheck`](https://github.com/smartiniOnGitHub/fastify-healthcheck) Fastify plugin to serve an health check route and a probe script.
|
|
88
89
|
- [`fastify-hemera`](https://github.com/hemerajs/fastify-hemera) Fastify Hemera plugin, for writing reliable & fault-tolerant microservices with [nats.io](https://nats.io/).
|
|
@@ -121,6 +122,7 @@ Plugins maintained by the fastify team are listed under [Core](#core) while plug
|
|
|
121
122
|
- [`fastify-orientdb`](https://github.com/mahmed8003/fastify-orientdb) Fastify OrientDB connection plugin, with which you can share the OrientDB connection across every part of your server.
|
|
122
123
|
- [`fastify-piscina`](https://github.com/piscinajs/fastify-piscina) A worker thread pool plugin using [Piscina](https://github.com/piscinajs/piscina).
|
|
123
124
|
- [`fastify-peekaboo`](https://github.com/simone-sanfratello/fastify-peekaboo) Fastify plugin for memoize responses by expressive settings.
|
|
125
|
+
- [`fastify-postgraphile`](https://github.com/alemagio/fastify-postgraphile) Plugin to integrate [PostGraphile](https://www.graphile.org/postgraphile/) in a Fastify project.
|
|
124
126
|
- [`fastify-prettier`](https://github.com/hsynlms/fastify-prettier) A fastify plugin that uses [prettier](https://github.com/prettier/prettier) under the hood to beautify outgoing responses and/or other things in the fastify server.
|
|
125
127
|
- [`fastify-qrcode`](https://github.com/chonla/fastify-qrcode) This plugin utilizes [qrcode](https://github.com/soldair/node-qrcode) to generate QR Code.
|
|
126
128
|
- [`fastify-qs`](https://github.com/webdevium/fastify-qs) A plugin for Fastify that adds support for parsing URL query parameters with [qs](https://github.com/ljharb/qs).
|
|
@@ -143,6 +145,7 @@ Plugins maintained by the fastify team are listed under [Core](#core) while plug
|
|
|
143
145
|
- [`fastify-sse-v2`](https://github.com/nodefactoryio/fastify-sse-v2) to provide Server-Sent Events using Async Iterators (supports newer versions of Fastify).
|
|
144
146
|
- [`fastify-tls-keygen`](https://gitlab.com/sebdeckers/fastify-tls-keygen) Automatically generate a browser-compatible, trusted, self-signed, localhost-only, TLS certificate.
|
|
145
147
|
- [`fastify-tokenize`](https://github.com/Bowser65/fastify-tokenize) [Tokenize](https://github.com/Bowser65/Tokenize) plugin for Fastify that removes the pain of managing authentication tokens, with built-in integration for `fastify-auth`.
|
|
148
|
+
- [`fastify-totp`](https://github.com/heply/fastify-totp) A plugin to handle TOTP (e.g. for 2FA)
|
|
146
149
|
- [`fastify-twitch-ebs-tools`](https://github.com/lukemnet/fastify-twitch-ebs-tools) Useful functions for Twitch Extension Backend Services (EBS).
|
|
147
150
|
- [`fastify-typeorm-plugin`](https://github.com/inthepocket/fastify-typeorm-plugin) Fastify plugin to work with TypeORM.
|
|
148
151
|
- [`fastify-vhost`](https://github.com/patrickpissurno/fastify-vhost) Proxy subdomain http requests to another server (useful if you want to point multiple subdomains to the same IP address, while running different servers on the same machine).
|
|
@@ -153,6 +156,8 @@ Plugins maintained by the fastify team are listed under [Core](#core) while plug
|
|
|
153
156
|
- [`fastify-webpack-hmr`](https://github.com/lependu/fastify-webpack-hmr) Webpack hot module reloading plugin for Fastify.
|
|
154
157
|
- [`fastify-ws`](https://github.com/gj/fastify-ws) WebSocket integration for Fastify — with support for WebSocket lifecycle hooks instead of a single handler function. Built upon [ws](https://github.com/websockets/ws) and [uws](https://github.com/uNetworking/bindings/tree/master/nodejs).
|
|
155
158
|
- [`fastify-xray`](https://github.com/jeromemacias/fastify-xray) Fastify plugin for AWS XRay recording.
|
|
159
|
+
- [`@gquittet/graceful-server`](https://github.com/gquittet/graceful-server) Tiny (~5k), Fast, KISS and dependency-free Node.JS library to make your Fastify API graceful.
|
|
156
160
|
- [`i18next-http-middleware`](https://github.com/i18next/i18next-http-middleware#fastify-usage) An [i18next](https://www.i18next.com) based i18n (internationalization) middleware to be used with Node.js web frameworks like express or `Fastify` and also for Deno.
|
|
157
161
|
- [`k-fastify-gateway`](https://github.com/jkyberneees/fastify-gateway) API Gateway plugin for `fastify`, a low footprint implementation that uses the `fastify-reply-from` HTTP proxy library.
|
|
162
|
+
- [`mercurius`](https://mercurius.dev/) A fully-featured and performant GraphQL server implementation for Fastify.
|
|
158
163
|
- [`openapi-validator-middleware`](https://github.com/PayU/openapi-validator-middleware#fastify) Swagger and OpenAPI 3.0 spec-based request validation middleware that supports `fastify`.
|
package/docs/Hooks.md
CHANGED
|
@@ -50,7 +50,6 @@ Or `async/await`:
|
|
|
50
50
|
fastify.addHook('onRequest', async (request, reply) => {
|
|
51
51
|
// Some code
|
|
52
52
|
await asyncMethod()
|
|
53
|
-
return
|
|
54
53
|
})
|
|
55
54
|
```
|
|
56
55
|
|
|
@@ -97,7 +96,6 @@ Or `async/await`:
|
|
|
97
96
|
fastify.addHook('preValidation', async (request, reply) => {
|
|
98
97
|
// Some code
|
|
99
98
|
await asyncMethod()
|
|
100
|
-
return
|
|
101
99
|
})
|
|
102
100
|
```
|
|
103
101
|
### preHandler
|
|
@@ -112,7 +110,6 @@ Or `async/await`:
|
|
|
112
110
|
fastify.addHook('preHandler', async (request, reply) => {
|
|
113
111
|
// Some code
|
|
114
112
|
await asyncMethod()
|
|
115
|
-
return
|
|
116
113
|
})
|
|
117
114
|
```
|
|
118
115
|
### preSerialization
|
|
@@ -200,7 +197,6 @@ Or `async/await`:
|
|
|
200
197
|
fastify.addHook('onResponse', async (request, reply) => {
|
|
201
198
|
// Some code
|
|
202
199
|
await asyncMethod()
|
|
203
|
-
return
|
|
204
200
|
})
|
|
205
201
|
```
|
|
206
202
|
|
|
@@ -220,7 +216,6 @@ Or `async/await`:
|
|
|
220
216
|
fastify.addHook('onTimeout', async (request, reply) => {
|
|
221
217
|
// Some code
|
|
222
218
|
await asyncMethod()
|
|
223
|
-
return
|
|
224
219
|
})
|
|
225
220
|
```
|
|
226
221
|
`onTimeout` is useful if you need to monitor the request timed out in your service. (if the `connectionTimeout` property is set on the fastify instance). The `onTimeout` hook is executed when a request is timed out and the http socket has been hanged up. Therefore you will not be able to send data to the client.
|
package/docs/Recommendations.md
CHANGED
|
@@ -6,6 +6,7 @@ This document contains a set recommendations, or best practices, when using
|
|
|
6
6
|
Fastify.
|
|
7
7
|
|
|
8
8
|
* [Use A Reverse Proxy](#reverseproxy)
|
|
9
|
+
* [Kubernetes](#kubernetes)
|
|
9
10
|
|
|
10
11
|
## Use A Reverse Proxy
|
|
11
12
|
<a id="reverseproxy"></a>
|
|
@@ -161,3 +162,19 @@ backend static-backend
|
|
|
161
162
|
[scale-horiz]: https://en.wikipedia.org/wiki/Scalability#Horizontal
|
|
162
163
|
[why-use]: https://web.archive.org/web/20190821102906/https://medium.com/intrinsic/why-should-i-use-a-reverse-proxy-if-node-js-is-production-ready-5a079408b2ca
|
|
163
164
|
[haproxy]: https://www.haproxy.org/
|
|
165
|
+
|
|
166
|
+
## Kubernetes
|
|
167
|
+
<a id="kubernetes"></a>
|
|
168
|
+
|
|
169
|
+
The `readinessProbe` uses [(by default](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes)) the pod IP as the hostname. Fastify listens on `127.0.0.1` by default. The probe will not be able to reach the application in this case. In order to make it work, the application must listen on `0.0.0.0` or specify a custom hostname in the `readinessProbe.httpGet` spec, as per the following example:
|
|
170
|
+
|
|
171
|
+
```yaml
|
|
172
|
+
readinessProbe:
|
|
173
|
+
httpGet:
|
|
174
|
+
path: /health
|
|
175
|
+
port: 4000
|
|
176
|
+
initialDelaySeconds: 30
|
|
177
|
+
periodSeconds: 30
|
|
178
|
+
timeoutSeconds: 3
|
|
179
|
+
successThreshold: 1
|
|
180
|
+
failureThreshold: 5
|
package/docs/Reply.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
- [.getHeaders()](#getheaders)
|
|
12
12
|
- [.removeHeader(key)](#removeheaderkey)
|
|
13
13
|
- [.hasHeader(key)](#hasheaderkey)
|
|
14
|
-
- [.redirect(dest)](#
|
|
14
|
+
- [.redirect([code,] dest)](#redirectcode--dest)
|
|
15
15
|
- [.callNotFound()](#callnotfound)
|
|
16
16
|
- [.getResponseTime()](#getresponsetime)
|
|
17
17
|
- [.type(contentType)](#typecontenttype)
|
|
@@ -44,7 +44,7 @@ and properties:
|
|
|
44
44
|
- `.removeHeader(key)` - Remove the value of a previously set header.
|
|
45
45
|
- `.hasHeader(name)` - Determine if a header has been set.
|
|
46
46
|
- `.type(value)` - Sets the header `Content-Type`.
|
|
47
|
-
- `.redirect([code,]
|
|
47
|
+
- `.redirect([code,] dest)` - Redirect to the specified url, the status code is optional (default to `302`).
|
|
48
48
|
- `.callNotFound()` - Invokes the custom not found handler.
|
|
49
49
|
- `.serialize(payload)` - Serializes the specified payload using the default json serializer or using the custom serializer (if one is set) and returns the serialized payload.
|
|
50
50
|
- `.serializer(function)` - Sets a custom serializer for the payload.
|
package/docs/Request.md
CHANGED
|
@@ -13,7 +13,7 @@ Request is a core Fastify object containing the following fields:
|
|
|
13
13
|
- `log` - the logger instance of the incoming request
|
|
14
14
|
- `ip` - the IP address of the incoming request
|
|
15
15
|
- `ips` - an array of the IP addresses in the `X-Forwarded-For` header of the incoming request (only when the [`trustProxy`](Server.md#factory-trust-proxy) option is enabled)
|
|
16
|
-
- `hostname` - the hostname of the incoming request
|
|
16
|
+
- `hostname` - the hostname of the incoming request (derived from `X-Forwarded-Host` header when the [`trustProxy`](Server.md#factory-trust-proxy) option is enabled)
|
|
17
17
|
- `protocol` - the protocol of the incoming request (`https` or `http`)
|
|
18
18
|
- `method` - the method of the incoming request
|
|
19
19
|
- `url` - the url of the incoming request
|
package/docs/Routes.md
CHANGED
|
@@ -302,7 +302,7 @@ See the `prefixTrailingSlash` route option above to change this behaviour.
|
|
|
302
302
|
<a name="custom-log-level"></a>
|
|
303
303
|
### Custom Log Level
|
|
304
304
|
It could happen that you need different log levels in your routes, Fastify achieves this in a very straightforward way.<br/>
|
|
305
|
-
You just need to pass the option `logLevel` to the plugin option or the route option with the [value](https://github.com/pinojs/pino/blob/master/docs/
|
|
305
|
+
You just need to pass the option `logLevel` to the plugin option or the route option with the [value](https://github.com/pinojs/pino/blob/master/docs/api.md#level-string) that you need.
|
|
306
306
|
|
|
307
307
|
Be aware that if you set the `logLevel` at plugin level, also the [`setNotFoundHandler`](Server.md#setnotfoundhandler) and [`setErrorHandler`](Server.md#seterrorhandler) will be affected.
|
|
308
308
|
|
|
@@ -431,6 +431,24 @@ fastify.inject({
|
|
|
431
431
|
})
|
|
432
432
|
```
|
|
433
433
|
|
|
434
|
+
> ## ⚠ Security Notice
|
|
435
|
+
> Remember to set a [`Vary`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary) header in your
|
|
436
|
+
> responses with the value you are using for defining the versioning (e.g.: `'Accept-Version'`),
|
|
437
|
+
> to prevent cache poisoning attacks. You can also configure this as part your Proxy/CDN.
|
|
438
|
+
>
|
|
439
|
+
> ```js
|
|
440
|
+
> const append = require('vary').append
|
|
441
|
+
> fastify.addHook('onSend', async (req, reply) => {
|
|
442
|
+
> if (req.headers['accept-version']) { // or the custom header you are using
|
|
443
|
+
> let value = reply.getHeader('Vary') || ''
|
|
444
|
+
> const header = Array.isArray(value) ? value.join(', ') : String(value)
|
|
445
|
+
> if ((value = append(header, 'Accept-Version'))) { // or the custom header you are using
|
|
446
|
+
> reply.header('Vary', value)
|
|
447
|
+
> }
|
|
448
|
+
> }
|
|
449
|
+
> })
|
|
450
|
+
> ```
|
|
451
|
+
|
|
434
452
|
If you declare multiple versions with the same major or minor, Fastify will always choose the highest compatible with the `Accept-Version` header value.<br/>
|
|
435
453
|
If the request will not have the `Accept-Version` header, a 404 error will be returned.
|
|
436
454
|
|
package/docs/Server.md
CHANGED
|
@@ -304,6 +304,8 @@ fastify.get('/', (request, reply) => {
|
|
|
304
304
|
})
|
|
305
305
|
```
|
|
306
306
|
|
|
307
|
+
**Note: if a request contains multiple <code>x-forwarded-host</code> or <code>x-forwarded-proto</code> headers, it is only the last one that is used to derive <code>request.hostname</code> and <code>request.protocol</code>**
|
|
308
|
+
|
|
307
309
|
<a name="plugin-timeout"></a>
|
|
308
310
|
### `pluginTimeout`
|
|
309
311
|
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Fastify Style Guide
|
|
2
|
+
|
|
3
|
+
## Welcome
|
|
4
|
+
|
|
5
|
+
Welcome to *Fastify Style Guide*. This guide is here to provide you with a conventional writing style for users writing developer documentation on our Open Source framework. Each topic is precise and well explained to help you write documentation users can easily understand and implement.
|
|
6
|
+
|
|
7
|
+
## Who is this guide for?
|
|
8
|
+
|
|
9
|
+
This guide is for anyone who loves to build with Fastify or wants to contribute to our documentation. You don't need to be an expert in writing technical documentation. This guide is here to help you.
|
|
10
|
+
|
|
11
|
+
Visit the [contribute](https://www.fastify.io/contribute) page on our website or read the [CONTRIBUTE.md](/CONTRIBUTING.md) file on Github to join our Open Source folks.
|
|
12
|
+
|
|
13
|
+
## Before you write
|
|
14
|
+
|
|
15
|
+
You need to know the following:
|
|
16
|
+
|
|
17
|
+
* JavaScript
|
|
18
|
+
* Node.js
|
|
19
|
+
* Git
|
|
20
|
+
* Github
|
|
21
|
+
* Markdown
|
|
22
|
+
* HTTP
|
|
23
|
+
* NPM
|
|
24
|
+
|
|
25
|
+
### Consider your Audience
|
|
26
|
+
|
|
27
|
+
Before you start writing, think about your audience. In this case, your audience should already know HTTP, JavaScript, NPM and NodeJs. It's necessary to keep your readers in mind because they are the one consuming your content. You want to give as much useful information as possible. Consider the vital things they need to know and how they can understand them. Make references and use words readers can relate with easily. Ask for feedback from the community: it can help you write better documentation that focuses on the user and what you want to achieve.
|
|
28
|
+
|
|
29
|
+
### Get straight to the point
|
|
30
|
+
|
|
31
|
+
Give your readers a clear and precise action to take. Start with what is most important. This way, you can help them find what they need faster. Mostly, readers tend to read the first content on a page, and many will not scroll further.
|
|
32
|
+
|
|
33
|
+
**Example**
|
|
34
|
+
|
|
35
|
+
Less like this: Colons are very important to register a parametric path. It lets the framework know there is a new parameter created. You can place the colon before the parameter name so the parametric path can be created.
|
|
36
|
+
|
|
37
|
+
More Like this: To register a parametric path, put a colon before the parameter name. Using a colon lets the framework know it is a parametric path and not a static path.
|
|
38
|
+
|
|
39
|
+
### Avoid adding video or image content
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
Do not add videos or screenshots in the documentation. It is easier to keep under version control. Videos and images will eventually end up becoming outdated as new updates keep developing. Instead, make a referral link or a youtube video. You can add links by using `[Title](www.websitename.com)` in the markdown.
|
|
43
|
+
|
|
44
|
+
**Example**
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
To learn more about hooks, See [Fastify hooks](https://www.fastify.io/docs/latest/Hooks).
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Result:
|
|
51
|
+
>To learn more about hooks, See [Fastify hooks](https://www.fastify.io/docs/latest/Hooks/).
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Avoid plagiarism
|
|
56
|
+
|
|
57
|
+
Make sure you avoid copying other people's work. Keep it as original as possible. You can learn from what they've done and also reference where it's from if you used a particular quote from their work.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Word Choice
|
|
61
|
+
|
|
62
|
+
There are a few things you need to use and avoid when writing your documentation to improve readability for readers and also make documentation neat, direct, and clean.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### When to use the second person "you" as the pronoun
|
|
66
|
+
|
|
67
|
+
When writing articles or guides, your content should communicate directly to readers in the second person ("you") addressed form. It is easier to give them direct instruction on what to do on a particular topic. To see an example, visit the [Plugins-guide.md](/docs/Plugins-Guide.md) page on Github.
|
|
68
|
+
|
|
69
|
+
**Example**
|
|
70
|
+
|
|
71
|
+
Less Like this: we can use the following plugins.
|
|
72
|
+
|
|
73
|
+
More like this: You can use the following plugins.
|
|
74
|
+
|
|
75
|
+
> According to [Wikipedia](#), ***You*** is usually a second person pronoun. Also, used to refer to an indeterminate person, as a more common alternative to a very formal indefinite pronoun.
|
|
76
|
+
|
|
77
|
+
## When to avoid second person "you" as the pronoun
|
|
78
|
+
|
|
79
|
+
One of the main rules of formal writing such as reference documentation, or API documentation, is to avoid second person ("you") or directly addressing the reader.
|
|
80
|
+
|
|
81
|
+
**Example**
|
|
82
|
+
|
|
83
|
+
Less Like this: You can use the following recommendation as an example.
|
|
84
|
+
|
|
85
|
+
More like this: As an example, the following recommendations should be referenced.
|
|
86
|
+
|
|
87
|
+
To view a live example, refer to the [Decorators.md](/docs/Decorators.md) reference document.
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
### Avoid using condescending terms
|
|
91
|
+
|
|
92
|
+
Condescending terms are words that include:
|
|
93
|
+
|
|
94
|
+
* Just
|
|
95
|
+
* Easy
|
|
96
|
+
* Simply
|
|
97
|
+
* Basically
|
|
98
|
+
* Obviously
|
|
99
|
+
|
|
100
|
+
The reader may not find it easy to use the Fastify's framework and plugins, avoid words that make it sound simple, easy, offensive, or insensitive. Not everyone who reads the documentation has the same level of understanding.
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
### Starting with a verb
|
|
104
|
+
|
|
105
|
+
Mostly start your description with a verb, which makes it simple and precise for the reader to follow. Prefer usage present tense because it's easier to read and understand than the past or future tense.
|
|
106
|
+
|
|
107
|
+
**Example**
|
|
108
|
+
|
|
109
|
+
Less like this: There is a need for Nodejs to be installed before you can be able to use Fastify.
|
|
110
|
+
|
|
111
|
+
More like this: Install Nodejs to make use of Fastify.
|
|
112
|
+
|
|
113
|
+
### Grammatical moods
|
|
114
|
+
|
|
115
|
+
Grammatical moods is a great way to express your writing. Avoid sounding too bossy while making a direct statement. Know when to switch between indicative, imperative, and subjunctive moods.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
**Indicative** - Use when making a factual statement or question.
|
|
119
|
+
|
|
120
|
+
Example: Since there is no testing framework available, "Fastify recommends ways to write tests".
|
|
121
|
+
|
|
122
|
+
**Imperative** - Use when giving instructions, actions, commands, or when you write your headings.
|
|
123
|
+
|
|
124
|
+
Example: Install dependencies before starting development.
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
**Subjunctive** - Use when making suggestions, hypothesis or non-factual statements.
|
|
128
|
+
|
|
129
|
+
Example: Reading the documentation on our website is recommended to get comprehensive knowledge of the framework.
|
|
130
|
+
|
|
131
|
+
### Use **active** voice instead of **passive**
|
|
132
|
+
|
|
133
|
+
Using active voice is a more compact and direct way of conveying your documentation.
|
|
134
|
+
|
|
135
|
+
**Example**
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
Passive: The node dependencies and packages are installed by npm.
|
|
139
|
+
|
|
140
|
+
Active: npm installs packages and node dependencies.
|
|
141
|
+
|
|
142
|
+
## Writing Style
|
|
143
|
+
|
|
144
|
+
### Documentation titles
|
|
145
|
+
|
|
146
|
+
When creating a new guide, API or reference in the `/docs/` directory, use short titles that best describe the topic of your documentation. Name your files in kebab-cases and avoid Raw or camelCase. To learn more about kebab-case you can visit this medium article on [Case Styles](https://medium.com/better-programming/string-case-styles-camel-pascal-snake-and-kebab-case-981407998841).
|
|
147
|
+
|
|
148
|
+
**Examples**: <br>
|
|
149
|
+
>`hook-and-plugins.md`, <br>
|
|
150
|
+
`adding-test-plugins.md`, <br>
|
|
151
|
+
`removing-requests.md`.
|
|
152
|
+
|
|
153
|
+
### Hyperlinks
|
|
154
|
+
|
|
155
|
+
Hyperlinks should have a clear title of what it references.
|
|
156
|
+
Here is how your hyperlink should look:
|
|
157
|
+
|
|
158
|
+
```MD
|
|
159
|
+
<!-- More like this -->
|
|
160
|
+
|
|
161
|
+
// Add clear & breif description
|
|
162
|
+
[Fastify Plugins] (https://www.fastify.io/docs/latest/Plugins/)
|
|
163
|
+
|
|
164
|
+
<!--Less like this -->
|
|
165
|
+
|
|
166
|
+
// incomplete description
|
|
167
|
+
[Fastify] (https://www.fastify.io/docs/latest/Plugins/)
|
|
168
|
+
|
|
169
|
+
// Adding title in link brackets
|
|
170
|
+
[](https://www.fastify.io/docs/latest/Plugins/ "fastify plugin")
|
|
171
|
+
|
|
172
|
+
// Empty title
|
|
173
|
+
[](https://www.fastify.io/docs/latest/Plugins/)
|
|
174
|
+
|
|
175
|
+
// Adding links localhost URL's instead of using code strings (``)
|
|
176
|
+
[http://localhost:3000/](http://localhost:3000/)
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
You can include in your documentation as many essential references as possible, but avoid having numerous links when writing for beginners to avoid distractions.
|