New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve getting started #462
Conversation
docs/Getting-Started.md
Outdated
```js | ||
const fastify = require('fastify')() | ||
|
||
fastify.register(require('./our-db-connector'), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should note somewhere that there is fastify-mongodb
docs/Getting-Started.md
Outdated
<a name="schema"></a> | ||
### Schema serialization | ||
Fastify is designed for performance. To truly turbocharge our server, we can serialize responses according to the [JSON Schema](http://json-schema.org/) standard: | ||
Do you prefer to use `async/await`? We got you covered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should recommend https://github.com/mcollina/make-promises-safe
0011022
to
cfc5ccf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not finished reviewing, and will surely find more changes to request. But it's time for me to head to lunch and I wanted to give you some feedback while you still have time to consider it and incorporate it given our timezone difference. So I'm submitting halfway through my review.
docs/Getting-Started.md
Outdated
@@ -1,13 +1,18 @@ | |||
<h1 align="center">Fastify</h1> | |||
|
|||
## Getting Started | |||
Hello! Thank you for checking out Fastify! | |||
This document aims to be a gentle introduction to the framework and its features. You will find some easy explanation, examples and link to other parts of the documentation if you want to get deepen in some argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This document aims to be a gentle introduction to the framework and its features.
You will find some easy explanation,It is an elementary introduction with examples and links to other parts of the documentation.if you want to get deepen in some argument.
docs/Getting-Started.md
Outdated
<a name="schema"></a> | ||
### Schema serialization | ||
Fastify is designed for performance. To truly turbocharge our server, we can serialize responses according to the [JSON Schema](http://json-schema.org/) standard: | ||
Do you prefer to use `async/await`? We got you covered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you prefer to use
async/await
?We got you coveredFastify supports it out-of-the-box.
docs/Getting-Started.md
Outdated
### Schema serialization | ||
Fastify is designed for performance. To truly turbocharge our server, we can serialize responses according to the [JSON Schema](http://json-schema.org/) standard: | ||
Do you prefer to use `async/await`? We got you covered. | ||
*(we also suggest to use [make-promises-safe](https://github.com/mcollina/make-promises-safe) to avoid file descriptor and memory leaks)* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(we also suggest
to useusing make-promises-safe to avoid file descriptor and memory leaks)
// Declare a route with an output schema | ||
fastify.get('/', opts, function (request, reply) { | ||
reply.send({ hello: 'world' }) | ||
fastify.get('/', async (request, reply) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the reply
parameter even need to be supplied?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if you need to set some custom header o change the status code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe a note about it and why it isn't being used here would be good to have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that a note could be a nice idea, but I think that this document should provide just a getting started, we have provided the link to other parts of the documentation that explains better the usage of every api. I don't think that add here too many info could be a good idea.
docs/Getting-Started.md
Outdated
@@ -56,61 +44,167 @@ fastify.listen(3000, function (err) { | |||
}) | |||
``` | |||
|
|||
*To learn more about using serialization and validation, see [Validation and Serialization](https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md)!* | |||
Awesome, that was easy. | |||
Unfortunately, write a complex application requires definitely more code than what we wrote above. A classic problem when you are building a new application is how handle multiple files, asynchronous bootstrapping and the architecture of your code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately,
writewriting a complex application requiresdefinitelysignificantly more code thanwhat we wrote abovethis example.
### Install | ||
``` | ||
npm i fastify --save | ||
``` | ||
<a name="first-server"></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> <a id="first-server"></a>
<a name="register"></a> | ||
### Register | ||
As you can see, using Fastify is very easy and handy. Obviously, registering all of your routes in the same file is not a good idea, so Fastify offers a utility to solve this problem, `register`: | ||
<a name="first-plugin"></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> <a id="first-plugin"></a>
docs/Getting-Started.md
Outdated
As you can see, using Fastify is very easy and handy. Obviously, registering all of your routes in the same file is not a good idea, so Fastify offers a utility to solve this problem, `register`: | ||
<a name="first-plugin"></a> | ||
### Your first plugin | ||
As in javascript everything is an object, in Fastify everything is a plugin. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As
in javascriptwith Javascript where everything is an object,inwith Fastify everything is a plugin.
docs/Getting-Started.md
Outdated
### Your first plugin | ||
As in javascript everything is an object, in Fastify everything is a plugin. | ||
Before digging into it, let's see how it works! | ||
Let's declare our basic server, but instead of declare the route inside the entry point, we'll declare it in an external file (checkout the [route declaration](https://github.com/fastify/fastify/blob/master/docs/Routes.md) docs). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's declare our basic server, but instead of
declaredeclaring the route inside the entry point, we'll declare it in an external file (checkout the route declaration docs).
docs/Getting-Started.md
Outdated
if (err) throw err | ||
module.exports = routes | ||
``` | ||
As you can see we used the `register` api, that you will use a lot when working with Fastify, since is the only way to register routes, plugins and so on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can seeIn this example we used theregister
apiAPI., that you will use a lot when working with Fastify, since is the only way to register routes, plugins and so on.This API is the core of the Fastify framework, and is the only way to register routes, plugins and so on.
cfc5ccf
to
b96daf8
Compare
@jsumners I have addressed almost all your suggestions, thanks! |
docs/Getting-Started.md
Outdated
if (err) throw err | ||
module.exports = routes | ||
``` | ||
In this we used the `register` API. This API is the core of the Fastify framework, and is the only way to register routes, plugins and so on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this [example] we used...
docs/Getting-Started.md
Outdated
``` | ||
In this we used the `register` API. This API is the core of the Fastify framework, and is the only way to register routes, plugins and so on. | ||
|
||
At the beginning of this document we said that Fastify helps you on handling the asynchronous bootstrapping of your application. Why this is important? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the beginning of this
documentguide wesaidnoted that Fastifyhelps you on handlingprovides a foundation that assists with the asynchronous bootstrapping ofyouran application. Why this is important?
docs/Getting-Started.md
Outdated
In this we used the `register` API. This API is the core of the Fastify framework, and is the only way to register routes, plugins and so on. | ||
|
||
At the beginning of this document we said that Fastify helps you on handling the asynchronous bootstrapping of your application. Why this is important? | ||
Well, let's say you must connect to database to fetch some data, obviously you don't want that the server starts accept requests before the database connection has been established. How can you address this problem? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, let's say you must connect to database to fetch some data, obviously you don't want that the server starts accept requests before the database connection has been established. How can you address this problem?
Consider the scenario where a database connection is needed to handle data storage. Obviously the database connection needs to be available prior to the server accepting connections. How do we address this problem?
docs/Getting-Started.md
Outdated
|
||
At the beginning of this document we said that Fastify helps you on handling the asynchronous bootstrapping of your application. Why this is important? | ||
Well, let's say you must connect to database to fetch some data, obviously you don't want that the server starts accept requests before the database connection has been established. How can you address this problem? | ||
Usually you will work with some complex callback/promises system that will mix the framework api with other libraries and your code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually you will work with some complex callback/promises system that will mix the framework api with other libraries and your code.
A typical solution is to use a complex callback, or promises, system that will mix the framework API with other libraries and the application code.
docs/Getting-Started.md
Outdated
At the beginning of this document we said that Fastify helps you on handling the asynchronous bootstrapping of your application. Why this is important? | ||
Well, let's say you must connect to database to fetch some data, obviously you don't want that the server starts accept requests before the database connection has been established. How can you address this problem? | ||
Usually you will work with some complex callback/promises system that will mix the framework api with other libraries and your code. | ||
Fastify handles this internally for you, with the minimum effort! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fastify handles this internally
for you,withtheminimum effort!
docs/Getting-Started.md
Outdated
<a name="extend-server"></a> | ||
### Extend your server | ||
Fastify is built to be extremely extensible and it's very minimal, we believe that provide a fully featured framework is not needed, since it will probably give you more than what you need. | ||
In other words, Fastify is not batteries included and if you need them, checkout our amazing [ecosystem](https://github.com/fastify/fastify/blob/master/docs/Ecosystem.md)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words, Fastify is not
batteries includeda "batteries included" framework, andif you need them, checkout ourrelies on an amazing ecosystem!
docs/Getting-Started.md
Outdated
|
||
<a name="test-server"></a> | ||
### Test your server | ||
We not offer a testing framework, but we do recommend a way to write your test that uses in a smart way the features and the architecture of Fastify. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We notFastify does not offer a testing framework, but we do recommend a way to write yourtesttests that usesin a smart waythe features and the architecture of Fastify.
docs/Getting-Started.md
Outdated
<a name="test-server"></a> | ||
### Test your server | ||
We not offer a testing framework, but we do recommend a way to write your test that uses in a smart way the features and the architecture of Fastify. | ||
Checkout the [testing](https://github.com/fastify/fastify/blob/master/docs/Testing.md) documentation! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checkout the testing documentation!
Read the testing documentation to learn more.
docs/Getting-Started.md
Outdated
### Run from CLI | ||
You can also run Fastify from the CLI thanks to [fastify-cli](https://github.com/fastify/fastify-cli). It's very easy! Simply add the following lines to your `package.json`: | ||
### Run your server from CLI | ||
You can also run Fastify from the CLI thanks to [fastify-cli](https://github.com/fastify/fastify-cli). It's very easy! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also runFastify also hasfrom theCLI integration thanks to fastify-cli. It's very easy!
docs/Getting-Started.md
Outdated
You can also run Fastify from the CLI thanks to [fastify-cli](https://github.com/fastify/fastify-cli). It's very easy! Simply add the following lines to your `package.json`: | ||
### Run your server from CLI | ||
You can also run Fastify from the CLI thanks to [fastify-cli](https://github.com/fastify/fastify-cli). It's very easy! | ||
Simply add the following lines to your `package.json`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simply add the following lines to
yourpackage.json
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work (as always)!
docs/Getting-Started.md
Outdated
|
||
fastify.listen(8000, function (err) { | ||
fastify.listen(3000, function (err) { | ||
if (err) throw err | ||
console.log(`server listening on ${fastify.server.address().port}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fastify.log.info('...')
?
### Schema serialization | ||
Fastify is designed for performance. To truly turbocharge our server, we can serialize responses according to the [JSON Schema](http://json-schema.org/) standard: | ||
Do you prefer to use `async/await`? Fastify supports it out-of-the-box. | ||
*(we also suggest using [make-promises-safe](https://github.com/mcollina/make-promises-safe) to avoid file descriptor and memory leaks)* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is out of the context. Maybe a recommendation is better for this tips
@@ -56,61 +44,167 @@ fastify.listen(3000, function (err) { | |||
}) | |||
``` | |||
|
|||
*To learn more about using serialization and validation, see [Validation and Serialization](https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md)!* | |||
Awesome, that was easy. | |||
Unfortunately, writing a complex application requires significantly more code than this example. A classic problem when you are building a new application is how handle multiple files, asynchronous bootstrapping and the architecture of your code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a new application is how handle multiple files
=> a new application is how handling multiple files
*To learn more about using serialization and validation, see [Validation and Serialization](https://github.com/fastify/fastify/blob/master/docs/Validation-and-Serialization.md)!* | ||
Awesome, that was easy. | ||
Unfortunately, writing a complex application requires significantly more code than this example. A classic problem when you are building a new application is how handle multiple files, asynchronous bootstrapping and the architecture of your code. | ||
Fastify offers an easy platform that helps solve all of problems, and more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that helps solve
=> that helps solving
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or add a "these" between "of" and "problems".
docs/Getting-Started.md
Outdated
something: true | ||
fastify.listen(3000, function (err) { | ||
if (err) throw err | ||
console.log(`server listening on ${fastify.server.address().port}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fastify.log.info
?
docs/Getting-Started.md
Outdated
Fastify is built to be extremely extensible and it's very minimal, we believe that provide a fully featured framework is not needed, since it will probably give you more than what you need. | ||
In other words, Fastify is not batteries included and if you need them, checkout our amazing [ecosystem](https://github.com/fastify/fastify/blob/master/docs/Ecosystem.md)! | ||
|
||
<a name="test-server"></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> <a id="test-server"></a>
docs/Getting-Started.md
Outdated
### Test your server | ||
We not offer a testing framework, but we do recommend a way to write your test that uses in a smart way the features and the architecture of Fastify. | ||
Checkout the [testing](https://github.com/fastify/fastify/blob/master/docs/Testing.md) documentation! | ||
|
||
<a name="cli"></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=><a id="cli"></a>
@@ -271,6 +270,26 @@ module.exports = fp(dbPlugin) | |||
``` | |||
You can also tell to `fastify-plugin` to check the installed version of Fastify, in case of you need a specific api. | |||
|
|||
<a name="handle-errors"></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> <a id="handle-errors"></a>
<a name="url-building"></a> | ||
### Url building | ||
Fastify supports both static and dynamic urls. | ||
To register a **parametric** path, use the *colon* before the parameter name. For **wildcard** use the *star*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> To register a **parametric** path, use the *colon* (`:`) before the parameter name. For **wildcard** use the *star*` (`*`)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed, there is an example few line below and everybody know what is a column and what is a star :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"star" => "asterisk"
docs/Routes.md
Outdated
In this case as parameter separator it's possible to use whatever character is not matched by the regular expression. | ||
|
||
Having a route with multiple parameters may affect negatively the performance, so prefer single parameter approach whenever possible, especially on routes which are on the hot path of your application. | ||
If you are interested hon how we handle the routing, checkout [find-my-way](https://github.com/delvedor/find-my-way). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> If you are interested in
b96daf8
to
f5e0687
Compare
I've addressed almost all suggestions, please take a final look :) |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Fastify has different concepts that are not present in the other frameworks and our getting started section is failing to show them and give a gentle introduction to the framework.
This pr aims to fix that, please review it :)