Preface

FastAPI is a Python-based asynchronous web framework for building fast and performant APIs (REST or GraphQL) that has seen great growth in popularity over the last couple of years. It enables developers to create flexible and powerful standards-compliant APIs as it is based on Python type hinting, it provides automatic documentation out of the box, and its performance is comparable to APIs developed in Go or Node.js.

React is arguably still the most popular solution for building user interfaces on the web. It is a library that adopts a declarative approach and simplifies the workflow by allowing developers to use only JavaScript or JSX, without a templating engine. With frameworks such as Next.js and a Node.js server, React enables us to create server-side generated or statically created web pages, while it is relatively easy to reuse an existing code base in React Native (for native applications), and with the plethora of third-party libraries, one of the strongest online communities, and the introduction of the Hooks mechanism, it has you covered whatever your specific need might be.

MongoDB is the most popular NoSQL database solution and offers numerous benefits – it is flexible and schemaless, it’s ideal for rapid prototyping, and it is also highly scalable and fast.

Combined together, these technologies blend very well, and though they bear a funny acronym (the FARM stack), they allow for a pleasant and fast developer experience, offer speed and flexibility, but most importantly, the opportunity to peruse the wide Python ecosystem, which is suitable for the most diverse problems – from data science and machine learning to analytics and image processing, task automation, and more.

This book aims to teach you how to design, build and deploy fast, scalable, standards-compliant, and flexible full-stack applications in an efficient and, hopefully, fun way. By the end of this book, you should be comfortable modeling the most diverse business problems with fluid requirements through a set of modern technologies and online services.

Who this book is for

This book is for backend and frontend JavaScript and Python developers or really anyone who wants to or needs to create web applications or sites within a flexible environment – websites that can include data processing or automation pipelines, but also simple websites for structured content. Basic knowledge of Python and JavaScript is assumed, while a general knowledge of the basics of the HTTP protocol and REST API concepts will be beneficial but is not mandatory. Minimal knowledge of CSS and HTML will be helpful.

What this book covers

Chapter 1, Web Development and the FARM Stack, starts with a brief introduction to the problems of the modern web and provides an analysis of the components of the stack and their benefits.

Chapter 2, Setting Up the Document Store with MongoDB, provides a quick but operative introduction to MongoDB through simple illustrative examples that will enable you to start prototyping quickly.

Chapter 3, Getting Started with FastAPI, explores the basics of the FastAPI framework, as well as the foundations upon which it is built: types, its asynchronous nature, and how it handles typical web-related tasks.

Chapter 4, Setting Up a React Workflow, is a very basic introduction to the React library and its basic features that enable developers to create simple or complex user interfaces. A brief introduction to JSX, React Hooks, and the handling of state and events is provided.

Chapter 5, Building the Backend for Our Application, teaches you how to create a basic backend with CRUD functionality using FastAPI and MongoDB and how to make it available through a Heroku deployment.

Chapter 6, Building the Frontend of the Application, continues the previous example and shows how to build a minimal React-based frontend for our application using the latest version of React Router for navigation.

Chapter 7, Authentication and Authorization, provides a practical introduction to JWT (JSON Web Token) based authentication and its implementation with FastAPI and React.

Chapter 8, Server-Side Rendering and Image Processing with FastAPI and Next.js, provides an introduction to the Next.js framework and its various page rendering methods as well as an image processing pipeline based on Cloudinary and the Python Pillow module. Finally, it shows how an application can be deployed on Vercel.

Chapter 9, Building a Data Visualization App with the FARM Stack, shows how to achieve various functionalities that might be needed in a modern web application – sending emails, displaying charts or dashboards based on data, creating reports, and more.

Chapter 10, Caching with Redis and Deployment on Ubuntu (DigitalOcean) and Netlify, provides an in-depth guide to deployment of FastAPI on a Ubuntu server with Nginx on a popular platform and the use of Netlify for the frontend.

Chapter 11, Useful Resources and Project Ideas, concludes with some useful tips and considerations regarding the various stack components and provides some project ideas for further development.

To get the most out of this book

You will need Python 3.6 or later installed on your computer, as well as Node.js 16 (or later). You should also have the basic knowledge needed to install packages with pip (Python) and npm or yarn (Node.js).

For the deployment of the projects, you will need to create accounts on MongoDB, Heroku, Vercel, Netlify, and Cloudinary (free). For the deployment on DigitalOcean, the cheapest solution is suggested (at the time of writing, 5 USD per month). I have tried to use the cheapest and, where possible, free tiers of the services so you can try before you find a solution that works well for you.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Full-Stack-FastAPI-React-and-MongoDB. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/Qat1m.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “Let’s open our .env file and set up Cloudinary.”

A block of code is set as follows:

from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
    return {"message": "Hello FastAPI"}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

import shutil
from fastapi import FastAPI, Form, File, UploadFile
app = FastAPI()

Any command-line input or output is written as follows:

uvicorn chapter3_first_endpoint:app --reload

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “You must explicitly set that on your Cloudinary settings page, under the Uploads tab – Enable unsigned uploading.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Full Stack FastAPI, React, and MongoDB, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.218.147