Git Product home page Git Product logo

accelerating-server-side-development-with-fastify's Introduction

Accelerating-Server-Side-Development-with-Fastify

This is the code repository for Accelerating Server-Side Development with Fastify, published by Packt.

A comprehensive guide to API development for building a scalable backend for your web apps

What is this book about?

This book is a complete guide to server-side app development in Fastify, written by the core contributors of this highly performant plugin-based web framework. Throughout the book, youโ€™ll discover how it fosters code reuse, thereby improving your time to market.

This book covers the following exciting features:

  • Explore the encapsulation techniques implemented by Fastify
  • Understand how to deploy, monitor, and handle errors in a running Fastify instance
  • Organize the project structure and implement a microservices architecture
  • Explore Fastify's core features such as code reuse, runtime speed, and much more
  • Discover best practices for implementing Fastify in real-world RESTful apps
  • Understand advanced backend development concepts such as performance monitoring and logging

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Instructions and Navigations

All of the code is organized into folders. For example, Chapter02.

The code will look like the following:

{
  "id": 1,
  "name": "Foo",
  "hobbies": [ "Soccer", "Scuba" ]
}

Following is what you need for this book: This book is for mid to expert-level backend web developers who have already used other backend web frameworks and are familiar with HTTP protocol and its peculiarities. Developers looking to migrate to Fastify, evaluate its suitability for their next project, avoid architecture pitfalls, and build highly responsive and maintainable API servers will also find this book useful. The book assumes knowledge of JavaScript programming, Node.js, and backend development.

With the following software and hardware list you can run all code files present in the book (Chapter 1-15).

Software and Hardware List

Chapter Software required OS required
1-15 Fastify 4 Windows, Mac OS X, and Linux (Any)

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. Click here to download it.

Related products

Get to Know the Authors

Manuel Spigolon is a senior backend developer at NearForm. He is one of the core maintainers on the Fastify team. Manuel has developed and maintained a complex API that serves more than 10 million users worldwide.

Maksim Sinik is a senior engineering manager and a core maintainer of the Fastify framework. He has a decade of experience as a Node.js developer with a strong interest in backend scalability. He designed the architecture and led the development of several service-based Software-as-a-Service (SaaS) platforms across multiple industries that process hundreds of thousands of requests.

Matteo Collina is the co-founder and CTO of Platformatic.dev who has the goal of removing all friction from backend development. He is also a prolific open source author in the JavaScript ecosystem, and the modules he maintains are downloaded more than 17 billion times a year. Previously, he was the chief software architect at NearForm, the best professional services company in the JavaScript ecosystem. In 2014, he defended his Ph.D. thesis titled Application Platforms for the Internet of Things. Matteo is a member of the Node.js Technical Steering Committee, focusing on streams, diagnostics, and HTTP. He is also the author of the fast logger, Pino, and the Fastify web framework. Matteo is a renowned international speaker after more than 60 conferences, including OpenJS World, Node.js Interactive, NodeConf.eu, NodeSummit, JSConf.Asia, WebRebels, and JsDay, to name just a few. Since August 2023, he also serves as a community director on the OpenJS Foundation. In the summer, he loves sailing the Sirocco.

Other books by the authors

accelerating-server-side-development-with-fastify's People

Contributors

doichev-kostia avatar drazen04 avatar eomm avatar fox1t avatar hedwards1997 avatar marquicodes avatar mcollina avatar packt-simrana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

accelerating-server-side-development-with-fastify's Issues

Some queries with respect to the Fastify Book

Hi there, I've been really enjoying the Fastify book on O'Reilly! The complete guide for the todo app has been fantastic for managing code. I do have a couple of questions:

  1. Usage of fastify.decorate in autoHooks:
    In the autoHooks files, we're using fastify.decorate('usersDataSource', {}). Why was this approach chosen over creating individual files like user.service.js and importing service functions separately? Does extensively decorating the fastify instance impact performance?

  2. onRequest hook in autoHooks for todos routes:
    We're adding service functions to request.todoDataSource in the onRequest hook. For instance:

fastify.decorateRequest('todosDataSource', null)

fastify.addHook('onRequest', async function (request, reply) {
  request.todosDataSource = {
    async countTodos(filter = {}) {
      filter.userId = request.user.id
      const totalCount = await todos.countDocuments(filter)
      return totalCount
    },
    // ...other functions
  }
})

Does adding all service functions on each request affect performance? Is there a more efficient way to handle this?

Thanks for your insights!

Chapter 3 - impossible to succeed with an excercise

In managing-the-routes-scope-nested.cjs, the parseUserHook() sets isAdmin: true if level is 42. However, level99Hook() needs a level higher than 99, thus it's never possible to reach /onlyAdmin successfully. Or am I missing something?

So maybe the condition in parseUserHook could be changed to e.g. level === 100 so that it's possible to satisfy both conditions :)

Invalid column name in csv parser (Chapter 8)

In the following snippet, the author uses the updatedAt property as one of the CSV headers. However, we actually use the modifiedAt field:

fastify.route({
    method: 'GET',
    url: '/export',
    schema: {
      querystring: fastify.getSchema('schema:todo:list:export')
    },
    handler: async function listTodo (request, reply) {
      const { title } = request.query

      // We manage the cursor as the data could be huge
      const cursor = await request.todosDataSource.listTodos({
        filter: { title },
        skip: 0,
        limit: undefined,
        asStream: true
      })

      reply.header('Content-Disposition', 'attachment; filename="todo-list.csv"')
      reply.type('text/csv')

      return cursor.pipe(csvStringify({
        quoted_string: true,
        header: true,
        columns: ['title', 'done', 'createdAt', 'updatedAt', 'id'],
        cast: {
          boolean: (value) => value ? 'true' : 'false',
          date: (value) => value.toISOString()
        }
      }))
    }
  })

Path: Chapter 8/routes/todos/files/routes.js
Chapter: 8
Section: Managing uploads and downloads

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.