REST APIs with Flask and Python

Video description

Learn techniques to develop industry-grade REST APIs with Python, Flask, Flask-RESTful, and FlaskSQLAlchemy

About This Video

  • Get to grips with the development of resource-based, production-ready REST APIs
  • Handle secure user registration and authentication with Flask
  • Understand deployment complexities and the performance of Flask REST APIs

In Detail

Are you intrigued by how REST APIs use HTTP requests to accept data from clients and return data accurately? Equipped with the necessary skills, you can also develop professional-grade REST APIs and take your software development career to the next level. This video course will teach you how you can build REST API with Python, using Flask. The course starts with a Python refresher, which will take you from the basics to some of the most advanced features of Python. You'll then explore various aspects of writing a REST API and get to grips with the Flask-RESTful API for more efficient development. As you advance, you’ll store and retrieve resources in an SQL database and simplify storage with Flask SQLAlchemy. Next, you’ll create user and item models and become familiar with the Git repository, workflow, and security. Finally, you’ll deploy Flask apps to Heroku and secure your REST API with DNS and SSL certificates. By the end of this course, you’ll have the developed skills and confidence to build REST APIs with Flask.

Publisher resources

Download Example Code

Table of contents

  1. Chapter 1 : Welcome!
    1. Promotion
  2. Chapter 2 : A Full Python Refresher
    1. Introduction to This Section
    2. Variables in Python
    3. Solution to Coding Exercise: Variables
    4. String Formatting in Python
    5. Getting User Input
    6. Writing Your First Python App
    7. Lists, Tuples, and Sets
    8. Advanced Set Operations
    9. Solution to Coding Exercise: Lists, Tuples, and Sets
    10. Booleans in Python
    11. If Statements
    12. The "in" Keyword in Python
    13. If Statements with the "in" Keyword
    14. Loops in Python
    15. Solution to Coding Exercise: Flow Control
    16. List Comprehensions in Python
    17. Dictionaries
    18. Destructuring Variables
    19. Functions in Python
    20. Function Arguments and Parameters
    21. Default Parameter Values
    22. Functions Returning Values
    23. Solution to Coding Exercise: Functions
    24. Lambda Functions in Python
    25. Dictionary Comprehensions
    26. Solution to Coding Exercise: Dictionaries and Students
    27. Unpacking Arguments
    28. Unpacking Keyword Arguments
    29. Object-Oriented Programming in Python
    30. Magic Methods: __str__ and __repr__
    31. Solution to Coding Exercise: Classes and Objects
    32. @classmethod and @staticmethod
    33. Solution to Coding Exercise: @classmethod and @staticmethod
    34. Class Inheritance
    35. Class Composition
    36. Type Hinting in Python 3.5+
    37. Imports in Python
    38. Relative Imports in Python
    39. Errors in Python
    40. Custom Error Classes
    41. First-Class Functions
    42. Simple Decorators in Python
    43. The "at" Syntax for Decorators
    44. Decorating Functions with Parameters
    45. Decorators with Parameters
    46. Mutability in Python
    47. Mutable Default Parameters (and Why They're a Bad Idea)
  3. Chapter 3 : Your First REST API
    1. Installing Flask
    2. Your First Flask Application
    3. HTTP Verbs
    4. REST Principles
    5. Creating Your Application Endpoints
    6. Returning a List of Stores
    7. Implementing Other Endpoints
    8. Calling the API from JavaScript
    9. Using Postman for API testing
  4. Chapter 4 : Flask-RESTful for More Efficient Development
    1. Virtualenvs and Setting up Flask-RESTful
    2. Your First Flask-RESTful API
    3. Test-First API Design—What Is That?
    4. Creating Your Item Resource
    5. The ItemList and Creating Items
    6. Improving Code and Error Control
    7. Authentication and Logging In — Part 1
    8. Authentication and Logging In — Part 2
    9. Using DELETE to Delete Items
    10. Using PUT to Create or Update Items
    11. Advanced Request Parsing with Flask-RESTful
    12. Optimising Your Final Code and Request Parsing
  5. Chapter 5 : Storing Resources in a SQL Database
    1. Setting up Your Project
    2. Running the SQLite Database and Interacting with It from Python
    3. Logging In and Retrieving Users from a Database
    4. Signing Up and Writing Users to a Database
    5. Preventing Duplicate Usernames When Signing Up Users
    6. Retrieving Your Item Resources from a Database
    7. Writing Your Item Resources to a Database
    8. Deleting Your Item Resources from the Database
    9. Refactoring Insertion of Items
    10. Using the PUT Method with Database Interaction
    11. Retrieving Many Items from the Database
  6. Chapter 6 : Simplifying Storage with Flask SQLAlchemy
    1. Setting up This Section's Project
    2. Improving the Project Structure and Maintainability
    3. Creating User and Item Models
    4. Verifying the App Using Postman
    5. Advanced Postman: Environments and Tests
    6. Tables and Columns in SQLAlchemy
    7. Implementing the ItemModel Using SQLAlchemy
    8. Implementing the UserModel Using SQLAlchemy
    9. Easily Displaying the ItemList Resource with SQLAlchemy
    10. No More Creating Tables Manually—Using SQLAlchemy to Create Tables
    11. Creating a New Model: StoreModel
    12. Creating the Store Resource
    13. Final Testing of This Section's API
  7. Chapter 7 : Git - Version Control
    1. Installing Git on Mac and Windows
    2. What is a Git Repository?
    3. The Git Workflow — Part 1
    4. The Git Workflow (Including GitHub) — Part 2
    5. Using SSH Keys for Security
    6. The README file
  8. Chapter 8 : Deploying Flask Apps to Heroku
    1. What is Heroku?
    2. Getting Your Code into GitHub
    3. Setting up Heroku for Flask
    4. Adding the Required Files to the Project
    5. Log in Heroku and Troubleshooting Errors
    6. Testing the Deployed API with Postman
    7. Adding PostgreSQL to Your Heroku App
    8. Working with Git and Automatic Deploys
  9. Chapter 9 : Deploying a Server to Your Own Server
    1. Setting up a DigitalOcean Server
    2. Installing PostgreSQL in Ubuntu 16.04
    3. Creating a UNIX User in Ubuntu 16.04
    4. Setting up Your New User with PostgreSQL Permissions
    5. Setting up nginx and REST API
    6. Setting up uWSGI to Run Your REST API
    7. Testing Your API to Make Sure Everything Works
  10. Chapter 10 : Security in Your Rest API
    1. Getting Your Domain Name
    2. Setting up Cloudflare
    3. What is Domain Name System (DNS)?
    4. Setting Your Domain Name System (DNS) Records
    5. Verifying Everything Works — This Is Important!
    6. Creating Your Secure Socket Layer (SSL) certificate in Cloudflare
    7. Configuring nginx for Secure Socket Layer (SSL)
  11. Chapter 11 : Token refreshing and Flask-JWT extended
    1. A Recap of the Code + a Few Changes!
    2. Creating a User Resource for Testing
    3. Testing Your New Resource with Postman
    4. Logging in with Flask-JWT-Extended
    5. Testing the Login with Postman
    6. Adding JWT Claims
    7. Getting the JWT Identity in and Endpoint and @jwt_optional
    8. What is a Fresh Token?
    9. Performing Token Refresh in Your Rest API
    10. Requiring a Fresh Token in an Endpoint
    11. Customizing Flask-JWT-Extended Callbacks and Responses
    12. Blacklisting with Flask-JWT-Extended
    13. Logging Out Users in Your Rest API

Product information

  • Title: REST APIs with Flask and Python
  • Author(s): Jose Salvatierra Fuentes
  • Release date: August 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781788621526