Accelerating Server-Side Development with Fastify A comprehensive guide to API development for building a scalable backend for your web apps

Learn to build faster web applications by implementing maintainable and pluggable APIs with Fastify Purchase of the print or Kindle book includes a free PDF eBook Key Features Written by Fastify's core contributors to help you adopt the Fastify mindset for API developmentGain an architectural o...

Full description

Saved in:
Bibliographic Details
Main Authors: Spigolon, Manuel, Sinik, Maksim, Collina, Matteo
Format: eBook
Language:English
Published: Birmingham Packt Publishing 2023
Packt Publishing, Limited
Packt Publishing Limited
Edition:1
Subjects:
ISBN:9781800568747, 1800568746, 9781800563582, 1800563582
Online Access:Get full text
Tags: Add Tag
No Tags, Be the first to tag this record!
Table of Contents:
  • Table of Contents What is Fastify?The Plugin System and the Boot ProcessWorking with RoutesExploring HooksExploring Validation and SerializationProject Structure and Configuration ManagementBuilding a RESTful APIAuthentication, Authorization, and File HandlingApplication TestingDeployment and Process monitoring for a healthy applicationMeaningful Application loggingFrom a Monolith to MicroservicesPerformance Assessment and ImprovementDeveloping a GraphQL APIType-Safe Fastify
  • Using Fastify type-providers -- Generating the API documentation -- Summary -- Index -- About Packt -- Other Books You May Enjoy
  • Declaring hooks -- Understanding the application lifecycle -- The onRoute hook -- The onRegister hook -- The onReady hook -- The onClose hook -- Understanding the request and reply lifecycle -- Handling errors inside hooks -- The onRequest hook -- The preParsing hook -- The preValidation hook -- The preHandler hook -- The preSerialization hook -- The onSend hook -- The onResponse hook -- The onError hook -- The onTimeout hook -- Replying from a hook -- Route-level hooks -- Summary -- Chapter 5: Exploring Validation and Serialization -- Technical requirements -- Understanding validation and serialization -- The JSON Schema specification -- Compiling a JSON Schema -- Fastify's compilers -- Understanding the validation process -- The validator compiler -- Validation execution -- Customizing the validator compiler -- Flow control -- Understanding the Ajv configuration -- Managing the validator compiler -- Configuring the default Ajv validator compiler -- The validation error -- Reusing JSON schemas -- Building a new validator compiler -- Customizing the schema validator compiler -- Understanding the serialization process -- The reply serializer -- The serializer compiler -- Managing the serializer compiler -- Summary -- Part 2: Build a Real-World Project -- Chapter 6: Project Structure and Configuration Management -- Technical requirements -- Designing the application structure -- Setting up the repository -- Understanding the application structure -- Improving the application structure -- Starting an optimal project -- Managing project directories -- Loading the configuration -- Debugging your application -- Sharing the application configuration across plugins -- Using Fastify's plugins -- How to get a project overview -- How to be reachable -- Summary -- Chapter 7: Building a RESTful API -- Technical requirements -- Application outline
  • Customizing logging configuration -- Enhancing the default logger configuration -- How to hide sensitive data -- Collecting the logs -- How to consolidate the logs -- Consolidating logs by using Pino transports -- Managing distributed logs -- Summary -- Part 3: Advanced Topics -- Chapter 12: From a Monolith to Microservices -- Technical requirements -- Implementing API versioning -- Version constraints -- URL prefixes -- Filesystem-based routing prefixes -- Splitting the monolith -- Creating our v2 service -- Building the v1 service on top of v2 -- Exposing our microservice via an API gateway -- docker-compose to emulate a production environment -- Nginx as an API gateway -- @fastify/http-proxy as an API gateway -- Implementing distributed logging -- Summary -- Chapter 13: Performance Assessment and Improvement -- Technical requirements -- Why measure performance? -- How to measure an application's performance? -- Measuring the HTTP response time -- Instrumenting the Fastify application -- Visualizing the tracing data -- How to analyze the data -- Creating a flame graph -- How to check memory issues -- How to identify I/O resources -- How to optimize the application -- Node.js internals that you need to know -- The safety of parallel running -- Connection management takeaways -- Summary -- Chapter 14: Developing a GraphQL API -- Technical requirements -- What is GraphQL? -- How does Fastify support GraphQL? -- Writing the GQL schema -- Defining GQL operations -- How to make live a GQL schema? -- Starting the GQL server -- Implementing our first GQL query resolver -- Implementing type object resolvers -- How to improve resolver performance? -- Managing GQL errors -- Summary -- Chapter 15: Type-Safe Fastify -- Technical requirements -- Creating the project -- Adding the tsconfig.json file -- Adding the application's entry point
  • Cover -- Title Page -- Copyright -- Dedication -- Contributors -- Table of Contents -- Preface -- Part 1: Fastify Basics -- Chapter 1: What Is Fastify? -- Technical requirements -- What is Fastify? -- Fastify's components -- Starting your server -- Lifecycle and hooks overview -- The root application instance -- Adding basic routes -- Shorthand declaration -- The handler -- The Reply component -- The first POST route -- The Request component -- Parametric routes -- Adding a basic plugin instance -- Understanding configuration types -- Shutting down the application -- Summary -- Chapter 2: The Plugin System and the Boot Process -- Technical requirements -- What is a plugin? -- Creating our first plugin -- The alternative plugin function signature -- Exploring the options parameter -- The options parameter type -- The prefix option -- Understanding encapsulation -- Handling the context -- fastify-plugin -- Exploring the boot sequence -- The register instance method -- The after instance method -- A declaration order -- Handling boot and plugin errors -- ERR_AVVIO_PLUGIN_TIMEOUT -- Recovery from a boot error -- Summary -- Chapter 3: Working with Routes -- Technical requirements -- Declaring API endpoints and managing the errors -- Declaration variants -- The route options -- Bulk routes loading -- Synchronous and asynchronous handlers -- Reply is a Promise -- How to reply with errors -- Routing to the endpoint -- The 404 handler -- Router application tuning -- Registering the same URLs -- Reading the client's input -- The path parameters -- The query string -- The headers -- The body -- Managing the route's scope -- The route server instance -- Printing the routes tree -- Adding new behaviors to routes -- Accessing the route's configuration -- AOP -- Summary -- Chapter 4: Exploring Hooks -- Technical requirements -- What is a lifecycle?
  • Defining routes -- Register routes -- Data source and model -- Implementing the routes -- createTodo -- listTodo -- readTodo -- updateTodo -- deleteTodo -- changeStatus -- Securing the endpoints -- Loading route schemas -- Schemas loader -- Adding the Autohooks plugin -- Implementing the Autohook plugin -- Using the schemas -- Don't repeat yourself -- Summary -- Chapter 8: Authentication, Authorization, and File Handling -- Technical requirements -- Authentication and authorization flow -- Building the authentication layer -- Authentication plugin -- Authentication routes -- Logout route -- Adding the authorization layer -- Adding the authentication layer -- Updating the to-do data source -- Managing uploads and downloads -- Summary -- Chapter 9: Application Testing -- Technical requirements -- Writing good tests -- What tests need to be written? -- How to write tests? -- Testing the Fastify application -- Installing the test framework -- Creating your node-tap cheatsheet test -- How to write tests with Fastify? -- How to improve the developer experience? -- Dealing with complex tests -- Reusing multiple requests -- Mocking the data -- Speeding up the test suite -- Running tests in parallel -- How to manage shared resources? -- Where tests should run -- Summary -- Chapter 10: Deployment and Process Monitoring for a Healthy Application -- Technical requirements -- Testing our Docker image with a local deployment -- Hosting our DB on MongoDB Atlas -- Choosing a cloud provider -- Deploying to Fly.io -- Setting up continuous deployment -- Collecting application process data -- Collecting the application process data with Prometheus -- Exploring the metrics with Grafana -- Summary -- Chapter 11: Meaningful Application Logging -- Technical requirements -- How to use Fastify's logger -- How Pino logs the application's messages
  • Accelerating Server-Side Development with Fastify: A comprehensive guide to API development for building a scalable backend for your web apps