Develop RESTful web services using the Flask micro-framework and integrate them using MySQL. Use Flask to develop, deploy, and manage REST APIs with easy-to-read and understand Python code. Solve your problem from a choice of libraries. Learn to use MySQL as the web services database for your Flask API using SQLAlchemy ORM.
Building REST APIs with Flask provides a primer on Flask, RESTful services, and working with pip to set up your virtual environment. The key differences between NoSQL and SQL are covered, and you are taught how to connect MySQL and Flask using SQLAlchemy. Author Kunal Relan presents best practices for creating REST APIs and guides you in structuring your app and testing REST endpoints. He teaches you how to set up authentication and render HTML using views. You learn how to write unit tests for your REST APIs, and understand mocks, assertions, and integration testing. You will know how to document your REST APIs, deploy your Flask application on all of the major cloud platforms, and debug and monitor your Flask application.
What You'll Learn
- Use MySQL to create Flask REST APIs
- Test REST endpoints
- Create CRUD endpoints with Flask and MySQL
- Deploy Flask on all of the major cloud platforms
- Monitor your Flask application
Who This Book Is For
Python developers interested in REST API development using Flask and web developers with basic programming knowledge who want to learn how Python and REST APIs work together. Readers should be familiar with Python (command line, or at least pip) and MySQL.
| About the Author |
|
ix | |
| About the Technical Reviewer |
|
xi | |
| Acknowledgments |
|
xiii | |
| Introduction |
|
xv | |
|
Chapter 1 Beginning with Flask |
|
|
1 | (26) |
|
|
|
1 | (3) |
|
|
|
2 | (1) |
|
Flask Components Covered in This Book |
|
|
3 | (1) |
|
Introduction to RESTful Services |
|
|
4 | (12) |
|
|
|
7 | (1) |
|
|
|
8 | (1) |
|
|
|
9 | (3) |
|
|
|
12 | (1) |
|
|
|
13 | (1) |
|
|
|
13 | (1) |
|
|
|
14 | (1) |
|
|
|
15 | (1) |
|
Setting Up Development Environment |
|
|
16 | (8) |
|
|
|
17 | (1) |
|
|
|
18 | (1) |
|
Understanding Python Virtual Environments |
|
|
19 | (5) |
|
|
|
24 | (2) |
|
|
|
25 | (1) |
|
|
|
26 | (1) |
|
Chapter 2 Database Modeling in Flask |
|
|
27 | (32) |
|
|
|
27 | (3) |
|
|
|
28 | (1) |
|
|
|
28 | (1) |
|
Key Differences: MySQL vs. MongoDB |
|
|
29 | (1) |
|
Creating a Flask Application with SQLAlchemy |
|
|
30 | (16) |
|
Creating an Author Database |
|
|
33 | (13) |
|
Sample Flask MongoEngine Application |
|
|
46 | (12) |
|
|
|
58 | (1) |
|
Chapter 3 CRUD Application with Flask (Part 1) |
|
|
59 | (38) |
|
|
|
88 | (8) |
|
|
|
96 | (1) |
|
Chapter 4 CRUD Application with Flask (Part 2) |
|
|
97 | (38) |
|
|
|
97 | (1) |
|
|
|
98 | (11) |
|
|
|
109 | (5) |
|
|
|
114 | (20) |
|
Building Blocks of API Documentation |
|
|
115 | (1) |
|
|
|
116 | (18) |
|
|
|
134 | (1) |
|
Chapter 5 Testing in Flask |
|
|
135 | (24) |
|
|
|
135 | (20) |
|
|
|
136 | (3) |
|
Unit Testing User Endpoints |
|
|
139 | (16) |
|
|
|
155 | (2) |
|
|
|
157 | (2) |
|
Chapter 6 Deploying Flask Applications |
|
|
159 | (24) |
|
Deploying Flask with uWSGI and Nginx on Alibaba Cloud ECS |
|
|
160 | (7) |
|
Deploying Flask on Gunicorn with Apache on Alibaba Cloud ECS |
|
|
167 | (5) |
|
Deploying Flask on AWS Elastic Beanstalk |
|
|
172 | (4) |
|
Deploying Flask App on Heroku |
|
|
176 | (4) |
|
|
|
177 | (3) |
|
Deploying Flask App on Google App Engine |
|
|
180 | (2) |
|
|
|
182 | (1) |
|
Chapter 7 Monitoring Flask Applications |
|
|
183 | (12) |
|
|
|
183 | (11) |
|
|
|
185 | (2) |
|
Flask Monitoring Dashboard |
|
|
187 | (2) |
|
|
|
189 | (3) |
|
|
|
192 | (2) |
|
|
|
194 | (1) |
| Index |
|
195 | |
Kunal Relan is an iOS security researcher and a full-stack developer with more than four years of experience in various fields of technology including network security, DevOps, cloud infrastructure, and application development working as a consultant with startups around the globe. He is an Alibaba Cloud MVP, and author of iOS Penetration Testing (Apress) and a variety of white papers. Kunal is a technology enthusiast and an active speaker. He regularly contributes to open source communities and writes articles for Digital Ocean and Alibaba Techshare.