<span><br></span><p><span>Build APIs and web apps based on Asynchronous Server Gateway Interface (ASGI). This book provides a comprehensive explanation of using Pydantic models to construct the request/response objects in a FASTAPI path operation. </span></p><p><span>You’ll start by reviewing type h
High-Performance Web Apps with FastAPI: The Asynchronous Web Framework Based on Modern Python
✍ Scribed by Malhar Lathkar
- Publisher
- Apress
- Tongue
- English
- Leaves
- 321
- Category
- Library
No coin nor oath required. For personal study only.
✦ Synopsis
Build APIs and web apps based on Asynchronous Server Gateway Interface (ASGI). This book provides a comprehensive explanation of using Pydantic models to construct the request/response objects in a FASTAPI path operation.
You’ll start by reviewing type hints in Python and the asynchronous processing concepts. One of the highlights of FastAPI is its auto generation of API docs. Pydantic library is the main pillar on top of which FastAPI is built. You’ll see that ASGI has a far better performance compared to most of the other popular Python frameworks as they implement Web server Gateway Interface (WSGI), which is synchronous in nature and hence having slower response time.
This book thoroughly explains how FastAPI interacts asynchronously with relational as well as NOSQL databases. Modern web apps use template engines to interact with the front-end. In this book, you will learn to use jinja2 templates and static assets. Swagger UI and OpenAPI standards are also covered in detail. Finally, different options of deployment of FastAPI app have been explored in this book.
This book uses practical examples to empower you to build high performance APIs
What You'll Learn
- Develop robust and high-performance web apps
- Deploy the FastAPI app for public availability using cloud services such as Deta and Docker container
- Understand the important building blocks of a web app such as form handling, templating and database interaction
Who This Book Is For
Aspiring and the experienced Python developers looking to leverage the flexibility of Python and the powerful features introduced in Modern Python. Computer science Engineering students at graduate and postgraduate level will also benefit immensely from the practical approach adapted in the book.
✦ Table of Contents
Table of Contents
About the Author
About the Technical Reviewer
Acknowledgments
Introduction
Chapter 1: Introduction to FastAPI
Type Hints
The typing Module
Asynchronous Processing
The asyncio Module
ASGI
About REST Architecture
What Is an API?
REST
REST Constraints
HTTP Verbs
POST Method
GET Method
PUT Method
DELETE Method
FastAPI Dependencies
Starlette
Pydantic
Uvicorn
Installation of FastAPI
Summary
Chapter 2: Getting Started with FastAPI
Hello World
Create an Application Object
Path Operation Decorator
Path Operation Function
Start Uvicorn
Externally Visible Server
Interactive API Docs
Swagger UI
Redoc
JSON Schema
Path Parameters
Using Type Hints
Type Parsing
Query Parameters
Optional Parameters
Order of Parameters
Validation of Parameters
Validating String Parameter
Validation with RegEx
Validating Numeric Parameters
Adding Metadata
Summary
Chapter 3: Request Body
POST Method
Body Parameters
Data Model with Pydantic
dataclasses Module
BaseModel
Pydantic Model As Parameter
Model Configuration
orm_mode
Pydantic Fields
Validation
Custom Validation
Nested Models
Summary
Chapter 4: Templates
HTML Response
Template Engine
Hello World Template
Template with Path Parameter
Template Variables
Passing dict in Template Context
Conditional Blocks in Template
Loop in Template
Serving Static Assets
Using JavaScript in Template
Static Image
CSS As a Static Asset
HTML Form Template
Retrieve Form Data
Summary
Chapter 5: Response
Response Model
Cookies
set_cookie() Method
Cookie Parameter
Headers
Header Parameter
Response Status Code
Response Types
HTMLResponse
JSONResponse
StreamingResponse
FileResponse
RedirectResponse
Summary
Chapter 6: Using Databases
DB-API
Creating the Books Table
Inserting a New Book
Selecting All Books
Selecting a Single Book
Updating a Book
Deleting a Book
aiosqlite Module
SQLAlchemy
async in SQLAlchemy
databases Module
Core Expression Language
Table Class Methods
FastAPI Path Operations
PyMongo for MongoDB
Motor for MongoDB
Summary
Chapter 7: Bigger Applications
Single File App
APIRouter
Router Package
Mounting Subapplications
Dependencies
Example of Dependency Injection
Query Parameters As Dependencies
Parameterized Dependency Function
Using Class As Dependency
Database Session Dependency
Dependency in Decorator
Middleware
CORS
Summary
Chapter 8: Advanced Features
WebSockets
How Do WebSockets Work?
WebSocket Server
WebSocket Client
WebSockets Module in FastAPI
Test WebSockets with Insomnia
Multiclient Chat Application
GraphQL
The Schema Definition Language
Queries
Mutations
Subscriptions
Schema
Strawberry GraphQL
FastAPI Events
Mounting WSGI Application
Summary
Chapter 9: Security and Testing
Exception Handling
User-Defined Exception
Security
Basic Access Authentication
OAuth
OAuth2PasswordBearer
Testing
Testing WebSocket
Testing Databases
Override Dependency
Override get_db()
AsyncClient
Summary
Chapter 10: Deployment
Hypercorn
HTTPS
Daphne
Gunicorn
FastAPI on Render Cloud
Docker
Google Cloud Platform
Deta Cloud
Summary
Index
📜 SIMILAR VOLUMES
Giunio De Luca, "FastAPI Cookbook: Develop high-performance APIs and web applications with Python" Enhance your web development skills, from setting up your environment and advanced integrations to building robust, high-traffic web applications with practical, scalable solutions Key Features
<p><span>Enhance your web development skills, from setting up your environment and advanced integrations to building robust, high-traffic web applications with practical, scalable solutions</span></p><h4><span>Key Features</span></h4><ul><li><span><span>Explore FastAPI in depth, from basic setup to
<p><b>Learn how to create your own websites simply, safely, and quickly with Django by tackling practical activities based on realistic case studies</b></p><h4>Key Features</h4><ul><li>Understand Django functionality and the Model-View-Template (MVT) paradigm</li><li>Create and iteratively build a b
<p><b>Learn how to create your own websites simply, safely, and quickly with Django by tackling practical activities based on realistic case studies</b></p><h4>Key Features</h4><ul><li>Understand Django functionality and the Model-View-Template (MVT) paradigm</li><li>Create and iteratively build a b
<p><span>Discover FastAPI features and best practices for building and deploying high-quality web APIs from scratch</span></p><h4><span>Key Features</span></h4><ul><li><span><span>A practical guide to developing production-ready web APIs rapidly in Python</span></span></li><li><span><span>Learn how