Skip to content

Commit

Permalink
Merge pull request #10 from fastify/improve-docs
Browse files Browse the repository at this point in the history
Move documentation into Guides or Reference subfolders
  • Loading branch information
Lachlan Collins authored Dec 1, 2021
2 parents cc8ecb8 + dfab6d5 commit 51a9228
Show file tree
Hide file tree
Showing 82 changed files with 1,121 additions and 1,264 deletions.
530 changes: 530 additions & 0 deletions docs/Docusaurus.md

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions docs/Benchmarking.md → docs/Guides/Benchmarking.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
title: Benchmarking
sidebar_label: Benchmarking
hide_title: false
---

Benchmarking is important if you want to measure how a change can affect the performance of your application. We provide a simple way to benchmark your application from the point of view of a user and contributor. The setup allows you to automate benchmarks in different branches and on different Node.js versions.
Expand Down
14 changes: 6 additions & 8 deletions docs/Guides/Contributing.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
title: Contributing
sidebar_label: Contributing
hide_title: false
---

Thank you for taking an interest in contributing to Fastify. We are excited
Expand All @@ -14,7 +12,7 @@ help us.
> [Developer Certificate of Origin](https://en.wikipedia.org/wiki/Developer_Certificate_of_Origin).
## Table Of Contents
<a name="contributing-toc"></a>
<a id="contributing-toc"></a>

- [Table Of Contents](#table-of-contents)
- [Types Of Contributions We're Looking For](#types-of-contributions-were-looking-for)
Expand All @@ -24,7 +22,7 @@ help us.
- [Using Visual Studio Code](#using-visual-studio-code)

## Types Of Contributions We're Looking For
<a name="contribution-types"></a>
<a id="contribution-types"></a>

In short, we welcome any type of contribution you are willing to provide. No
contribution is too small. We gladly accept contributions such as:
Expand All @@ -35,7 +33,7 @@ contribution is too small. We gladly accept contributions such as:
* Reporting previously unknown bugs by opening an issue with a minimal reproduction

## Ground Rules & Expectations
<a name="contributing-rules"></a>
<a id="contributing-rules"></a>

Before we get started, here are a few things we expect from you (and that
you should expect from others):
Expand All @@ -51,7 +49,7 @@ you should expect from others):
can merge your contribution.

## How To Contribute
<a name="contributing-how-to"></a>
<a id="contributing-how-to"></a>

If you'd like to contribute, start by searching through the
[issues](https://github.com/fastify/fastify/issues) and
Expand All @@ -71,15 +69,15 @@ https://github.com/github/opensource.guide/blob/2868efbf0c14aec821909c19e210c360
-->

## Setting Up Your Environment
<a name="contributing-environment"></a>
<a id="contributing-environment"></a>

Please adhere to the project's code and documentation style. Some popular tools
that automatically "correct" code and documentation do not follow a style that
conforms to the styles this project uses. Notably, this project uses
[StandardJS](https://standardjs.com) for code formatting.

### Using Visual Studio Code
<a name="contributing-vscode"></a>
<a id="contributing-vscode"></a>

What follows is how to use [Visual Studio Code (VSCode) portable](https://code.visualstudio.com/docs/editor/portable)
to create a Fastify specific environment. This guide is written as if you are
Expand Down
2 changes: 0 additions & 2 deletions docs/Ecosystem.md → docs/Guides/Ecosystem.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
title: Ecosystem
sidebar_label: Ecosystem
hide_title: false
---

Plugins maintained by the Fastify team are listed under [Core](#core) while plugins maintained by the community are listed in the [Community](#community) section.
Expand Down
45 changes: 21 additions & 24 deletions docs/Guides/Getting-Started.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
title: Getting Started
sidebar_label: Getting Started
hide_title: false
---

Hello! Thank you for checking out Fastify!
Expand All @@ -11,20 +9,19 @@ This document aims to be a gentle introduction to the framework and its features
Let's start!

### Install
<a name="install"></a>
<a id="install"></a>

Install with npm:
```bash
```
npm i fastify --save
```

Install with yarn:
```
yarn add fastify
```

### Your first server
<a name="first-server"></a>
<a id="first-server"></a>

Let's write our first server:
```js
Expand Down Expand Up @@ -108,13 +105,13 @@ Fastify offers an easy platform that helps to solve all of the problems outlined
> When deploying to a Docker (or another type of) container using `0.0.0.0` or `::` would be the easiest method for exposing the application.
### Your first plugin
<a name="first-plugin"></a>
<a id="first-plugin"></a>
As with JavaScript, where everything is an object, with Fastify everything is a plugin.
Before digging into it, let's see how it works!
Let's declare our basic server, but instead of declaring the route inside the entry point, we'll declare it in an external file (check out the [route declaration](../Routes.md) docs).
Let's declare our basic server, but instead of declaring the route inside the entry point, we'll declare it in an external file (check out the [route declaration](../Reference/Routes.md) docs).
```js
// ESM
import Fastify from 'fastify'
Expand Down Expand Up @@ -309,16 +306,16 @@ Let's recap what we have done here since we've introduced some new concepts.

As you can see, we used `register` for both the database connector and the registration of the routes.

This is one of the best features of Fastify, it will load your plugins in the same order you declare them, and it will load the next plugin only once the current one has been loaded. In this way, we can register the database connector in the first plugin and use it in the second *(read [here](../Plugins.md#handle-the-scope) to understand how to handle the scope of a plugin)*.
This is one of the best features of Fastify, it will load your plugins in the same order you declare them, and it will load the next plugin only once the current one has been loaded. In this way, we can register the database connector in the first plugin and use it in the second *(read [here](../Reference/Plugins.md#handle-the-scope) to understand how to handle the scope of a plugin)*.

Plugin loading starts when you call `fastify.listen()`, `fastify.inject()` or `fastify.ready()`

The MongoDB plugin uses the `decorate` API to add custom objects to the Fastify instance, making them available for use everywhere. Use of this API is encouraged to facilitate easy code reuse and to decrease code or logic duplication.

To dig deeper into how Fastify plugins work, how to develop new plugins, and for details on how to use the whole Fastify API to deal with the complexity of asynchronously bootstrapping an application, read [the hitchhiker's guide to plugins](../Plugins-Guide.md).
To dig deeper into how Fastify plugins work, how to develop new plugins, and for details on how to use the whole Fastify API to deal with the complexity of asynchronously bootstrapping an application, read [the hitchhiker's guide to plugins](./Plugins-Guide.md).

### Loading order of your plugins
<a name="plugin-loading-order"></a>
<a id="plugin-loading-order"></a>

To guarantee consistent and predictable behavior of your application, we highly recommend to always load your code as shown below:
```
Expand Down Expand Up @@ -354,7 +351,7 @@ As discussed previously, Fastify offers a solid encapsulation model, to help you
```

### Validate your data
<a name="validate-data"></a>
<a id="validate-data"></a>

Data validation is extremely important and a core concept of the framework.

Expand Down Expand Up @@ -382,10 +379,10 @@ fastify.post('/', opts, async (request, reply) => {
```
This example shows how to pass an options object to the route, which accepts a `schema` key that contains all of the schemas for route, `body`, `querystring`, `params`, and `headers`.

Read [Validation and Serialization](../Validation-and-Serialization.md) to learn more.
Read [Validation and Serialization](../Reference/Validation-and-Serialization.md) to learn more.

### Serialize your data
<a name="serialize-data"></a>
<a id="serialize-data"></a>

Fastify has first class support for JSON. It is extremely optimized to parse JSON bodies and to serialize JSON output.

Expand All @@ -409,12 +406,12 @@ fastify.get('/', opts, async (request, reply) => {
})
```
By specifying a schema as shown, you can speed up serialization by a factor of 2-3. This also helps to protect against leakage of potentially sensitive data, since Fastify will serialize only the data present in the response schema.
Read [Validation and Serialization](../Validation-and-Serialization.md) to learn more.
Read [Validation and Serialization](../Reference/Validation-and-Serialization.md) to learn more.

### Parsing request payloads
<a name="request-payload"></a>
<a id="request-payload"></a>

Fastify parses `'application/json'` and `'text/plain'` request payloads natively, with the result accessible from the [Fastify request](../Request.md) object at `request.body`.
Fastify parses `'application/json'` and `'text/plain'` request payloads natively, with the result accessible from the [Fastify request](../Reference/Request.md) object at `request.body`.

The following example returns the parsed body of a request back to the client:

Expand All @@ -425,24 +422,24 @@ fastify.post('/', opts, async (request, reply) => {
})
```

Read [Content-Type Parser](../ContentTypeParser.md) to learn more about Fastify's default parsing functionality and how to support other content types.
Read [Content-Type Parser](../Reference/ContentTypeParser.md) to learn more about Fastify's default parsing functionality and how to support other content types.

### Extend your server
<a name="extend-server"></a>
<a id="extend-server"></a>

Fastify is built to be extremely extensible and minimal, we believe that a bare-bones framework is all that is necessary to make great applications possible.

In other words, Fastify is not a "batteries included" framework, and relies on an amazing [ecosystem](../Ecosystem.md)!
In other words, Fastify is not a "batteries included" framework, and relies on an amazing [ecosystem](./Ecosystem.md)!

### Test your server
<a name="test-server"></a>
<a id="test-server"></a>

Fastify does not offer a testing framework, but we do recommend a way to write your tests that uses the features and architecture of Fastify.

Read the [testing](../Testing.md) documentation to learn more!
Read the [testing](./Testing.md) documentation to learn more!

### Run your server from CLI
<a name="cli"></a>
<a id="cli"></a>

Fastify also has CLI integration thanks to [fastify-cli](https://github.com/fastify/fastify-cli).

Expand Down Expand Up @@ -481,7 +478,7 @@ npm start
```

### Slides and Videos
<a name="slides"></a>
<a id="slides"></a>

- Slides
- [Take your HTTP server to ludicrous speed](https://mcollina.github.io/take-your-http-server-to-ludicrous-speed) by [@mcollina](https://github.com/mcollina)
Expand Down
18 changes: 8 additions & 10 deletions docs/Migration-Guide-V3.md → docs/Guides/Migration-Guide-V3.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
title: V3 Migration Guide
sidebar_label: V3 Migration Guide
hide_title: false
title: Migration Guide V3
---

This guide is intended to help with migration from Fastify v2 to v3.
Expand Down Expand Up @@ -38,8 +36,8 @@ fastify.use(require('cors')());

### Changed logging serialization ([#2017](https://github.com/fastify/fastify/pull/2017))

The logging [Serializers](./Logging.md) have been updated to now Fastify
[`Request`](./Request.md) and [`Reply`](./Reply.md) objects instead of
The logging [Serializers](../Reference/Logging.md) have been updated to now Fastify
[`Request`](../Reference/Request.md) and [`Reply`](../Reference/Reply.md) objects instead of
native ones.

Any custom serializers must be updated if they rely upon `request` or `reply`
Expand Down Expand Up @@ -272,14 +270,14 @@ fastify.get('/', (request, reply) => {

- Hooks now have consistent context regardless of how they are registered
([#2005](https://github.com/fastify/fastify/pull/2005))
- Deprecated `request.req` and `reply.res` for [`request.raw`](./Request.md) and
[`reply.raw`](./Reply.md) ([#2008](https://github.com/fastify/fastify/pull/2008))
- Deprecated `request.req` and `reply.res` for [`request.raw`](../Reference/Request.md) and
[`reply.raw`](../Reference/Reply.md) ([#2008](https://github.com/fastify/fastify/pull/2008))
- Removed `modifyCoreObjects` option ([#2015](https://github.com/fastify/fastify/pull/2015))
- Added [`connectionTimeout`](./Reference/Server.md#factory-connection-timeout)
- Added [`connectionTimeout`](../Reference/Server.md#factory-connection-timeout)
option ([#2086](https://github.com/fastify/fastify/pull/2086))
- Added [`keepAliveTimeout`](./Reference/Server.md#factory-keep-alive-timeout)
- Added [`keepAliveTimeout`](../Reference/Server.md#factory-keep-alive-timeout)
option ([#2086](https://github.com/fastify/fastify/pull/2086))
- Added async-await support for [plugins](./Plugins.md#async-await)
- Added async-await support for [plugins](../Reference/Plugins.md#async-await)
([#2093](https://github.com/fastify/fastify/pull/2093))
- Added the feature to throw object as error
([#2134](https://github.com/fastify/fastify/pull/2134))
Loading

0 comments on commit 51a9228

Please sign in to comment.