Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/webeetle/wetalk-fastify
We talk about Fastify
https://github.com/webeetle/wetalk-fastify
Last synced: about 2 months ago
JSON representation
We talk about Fastify
- Host: GitHub
- URL: https://github.com/webeetle/wetalk-fastify
- Owner: webeetle
- Created: 2020-04-01T06:41:11.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T01:05:42.000Z (about 2 years ago)
- Last Synced: 2023-03-02T20:56:28.571Z (almost 2 years ago)
- Language: JavaScript
- Size: 8.94 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# We talk about Fastify
## Example 1
A Basic example on fastify usage
```
const fastify = require('fastify')({ logger: true })// Declare a route for our application
fastify.get('/', async (req, res) => {
return { hello: 'world' }
})const startServer = async port => {
try {
await fastify.listen(port)
fastify.log.info(`Server started on http://localhost:${port}`)
} catch (e) {
fastify.log.error(e)
process.exit(1)
}
}startServer(3000)
```## Example 2
Our first route
```
async function routes (fastify, options) {
fastify.get('/', async (request, reply) => {
return { hello: 'World' }
})
}module.exports = routes
```## Example 3
Register multiple routes with different log level
```
fastify.register(require('./api-v1.js'), { prefix: '/v1', logLevel: 'error' })
fastify.register(require('./api-v2.js'), { prefix: '/v2' })
```## Example 4
Learn about JSON Schema and Hooks
```
fastify.route({
method: 'POST',
url: '/',
schema: {
body: S.object()
.prop('name', S.string().required()),
response: {
200: S.object()
.prop('message', S.string())
}
},
onRequest: async (request, reply) => {
fastify.log.info("onRequest")
},
preValidation: async (request, reply) => {
fastify.log.info("preValidation")
},
preHandler: async (request, reply) => {
fastify.log.info("preHandler")
},
preSerialization: async (request, reply) => {
fastify.log.info("preSerialization")
},
handler: async (request, reply) => {
const { name } = request.body
return { message: `Hello, ${name}` }
}
})
```## Example 5
Create Fastify App. Create a ticket CRUD example
- [Fluent Schema](https://github.com/fastify/fluent-schema)
- [Swagger](https://github.com/fastify/fastify-swagger)
- [Mongo DB](https://github.com/fastify/fastify-mongodb)
- [Fastify Plugin](https://github.com/fastify/fastify-plugin)## Example 6
Add JWT Authentication
- [Fluent Schema](https://github.com/fastify/fluent-schema)
- [Swagger](https://github.com/fastify/fastify-swagger)
- [Mongo DB](https://github.com/fastify/fastify-mongodb)
- [Fastify Plugin](https://github.com/fastify/fastify-plugin)
- [Fastify JWT](https://github.com/fastify/fastify-jwt)## Example 7
Split previous example in two microservices with an API gateway
- [Fluent Schema](https://github.com/fastify/fluent-schema)
- [Swagger](https://github.com/fastify/fastify-swagger)
- [Mongo DB](https://github.com/fastify/fastify-mongodb)
- [Fastify Plugin](https://github.com/fastify/fastify-plugin)
- [Fastify JWT](https://github.com/fastify/fastify-jwt)
- [Fastify HTTP Proxy](https://github.com/fastify/fastify-http-proxy)